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 be determined froml ⊕ r
, assumingl, r
to be integers. This value is equal topow(2, p) − 1
, wherep
is the smallest value such thatpow(2, p)
is larger thanl ⊕ r
.
Now, relating with the code,
val = 64 - __builtin_clzll(l ^ r); // p
(1LL << val) - 1; // pow(2, p) - 1
1
solved “Little girl and maximum XOR”