[Solved] “Little girl and maximum XOR”

If you read about __builtin_clzll in http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Other-Builtins.html — Built-in Function: int __builtin_clzll (unsigned long long x) Returns the number of leading 0-bits in x, starting at the most significant bit position. If x is 0, the result is undefined. From https://cs.stackexchange.com/a/29510, The maximum possible XOR of any two integers from an interval [l, r] can … Read more

[Solved] Bitwise shift operation choice

The reason it works this way is because C and C++ used << for left shift and >> for right shift long before Java. Those languages have both signed and unsigned types, and for signed types the sign bit was propagated in the right-shift case. Java does not have unsigned types, so they kept the … Read more

[Solved] What is the most efficient way to zero all bits below the most significant set bit?

There’s no single instruction that can do this. BMI1 blsi dst,src can isolate the lowest set bit, not the highest. i.e. x & -x. If x86 had a bit-reversed version of blsi, we could use that, but it doesn’t. But you can do much better than what you were suggesting. An all-zero input is always … Read more