You are viewing a single comment's thread. Return to all comments →
Simple O(1) solution: XOR a and b. Find its next power of 2. Subtract 1. Flip its bits and AND with either a or b.
a & ~(nextpowerof2(a^b)-1)
That's it.
Seems like cookies are disabled on this browser, please enable them to open this website
AND Product
You are viewing a single comment's thread. Return to all comments →
Simple O(1) solution:
XOR a and b. Find its next power of 2. Subtract 1. Flip its bits and AND with either a or b.
a & ~(nextpowerof2(a^b)-1)
That's it.