Switch on Enum (with Flags attribute) without declaring every possible combination?

How about this. Of course the arguments and return types of DoSomething, etc., can be anything you like. class Program { [Flags] public enum CheckType { Form = 1, QueryString = 2, TempData = 4, } private static bool DoSomething(IEnumerable cln) { Console.WriteLine(“DoSomething”); return true; } private static bool DoSomethingElse(IEnumerable cln) { Console.WriteLine(“DoSomethingElse”); return true; … Read more

Divide by 10 using bit shifts?

Editor’s note: this is not actually what compilers do, and gives the wrong answer for large positive integers ending with 9, starting with div10(1073741829) = 107374183 not 107374182 (Godbolt). It is exact for inputs smaller than 0x40000005, though, which may be sufficient for some uses. Compilers (including MSVC) do use fixed-point multiplicative inverses for constant … Read more

Can’t see MySQL BIT field value when using SELECT

The reason why you can’t see it in terminal is because bit values are non printable characters. Lets insert following values: INSERT INTO `my_table` (`ID`, `enabled`) VALUES (1,b’1′),(2,b’0′); Then select them to file: mysql> SELECT * FROM my_table INTO OUTFILE ‘/tmp/my_table.txt’ FIELDS TERMINATED BY ‘,’ ENCLOSED BY ‘”‘ LINES TERMINATED BY ‘\n’; First lets view … Read more

Generate all binary strings of length n with k bits set

This method will generate all integers with exactly N ‘1’ bits. From https://graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation Compute the lexicographically next bit permutation Suppose we have a pattern of N bits set to 1 in an integer and we want the next permutation of N 1 bits in a lexicographical sense. For example, if N is 3 and the … Read more

What USEFUL bitwise operator code tricks should a developer know about? [closed]

Using bitwise operations on strings (characters) Convert letter to lowercase: OR by space => (x | ‘ ‘) Result is always lowercase even if letter is already lowercase eg. (‘a’ | ‘ ‘) => ‘a’ ; (‘A’ | ‘ ‘) => ‘a’ Convert letter to uppercase: AND by underline => (x & ‘_’) Result is always … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)