bit操做 轉

http://www.catonmat.net/blog/low-level-bit-hacks-you-absolutely-must-know/.net

 

Bit Hack #6. Turn off the rightmost 1-bit.htm

y = x & (x-1)

Bit Hack #7. Isolate the rightmost 1-bit.blog

y = x & (-x)

Bit Hack #8. Right propagate the rightmost 1-bit.it

y = x | (x-1)

Bit Hack #9. Isolate the rightmost 0-bit.class

y = ~x & (x+1)

Bit Hack #10. Turn on the rightmost 0-bit.hack

y = x | (x+1)x y differ only 1 bitdif = x^yreturn dif && !( dif & (dif-1) )
相關文章
相關標籤/搜索