You are viewing a single comment's thread. Return to all comments →
You can use bit shifting and bitwise or checks to get your answer a lot quicker, you avoid doing any loops whatsoever.
(Edit: updated to reflect changes from godoh's comment)
int value = l ^ r; value |= value >> 1; value |= value >> 2; value |= value >> 4; value |= value >> 8; return value;
Seems like cookies are disabled on this browser, please enable them to open this website
Maximizing XOR
You are viewing a single comment's thread. Return to all comments →
You can use bit shifting and bitwise or checks to get your answer a lot quicker, you avoid doing any loops whatsoever.
(Edit: updated to reflect changes from godoh's comment)