http://www.catonmat.net/blog/low-level-bit-hacks-you-absolutely-must-know/
Bit Hack #6. Turn off the rightmost 1-bit.
y = x & (x-1)
Bit Hack #7. Isolate the rightmost 1-bit.
y = x & (-x)
Bit Hack #8. Right propagate the rightmost 1-bit.
y = x | (x-1)
Bit Hack #9. Isolate the rightmost 0-bit.
y = ~x & (x+1)
Bit Hack #10. Turn on the rightmost 0-bit.
y = x | (x+1)
时间: 2024-10-17 15:50:29