You are viewing a single comment's thread. Return to all comments →
I have a question, why did you have
int significantBit = 31 - Integer.numberOfLeadingZeros(xored);
Instead of 32, which represents the 32bits used for an int.
Using the base example of L = 10, R = 15
L ^ R = 1010 ^ 1111 = 0101 = 5
The result of Integer.numberOfLeadingZeros(xored) is 29, which matches 32bits - 3bits (for 5)
And then your result would be
int result = (1 << significantBit) - 1;
Just trying to learn on your reasoning to use 31.