Base 2 arithmetic and boolean tricks

Please Visit: http://lifelongprogrammer.blogspot.com



Base 2 arithmetic and boolean tricks

http://www.ugcs.caltech.edu/~wnoise/base2.html

x & (x-1)

= x with the lowest set bit cleared.

x & ~(x-1)

= extracts the lowest set bit of x (all others are clear)

x | (x+1)

= x with the lowest cleared bit set.

x | ~(x+1)

= extracts the lowest cleared bit of x (all others are set).



from Google Plus RSS Feed for 101157854606139706613 http://www.ugcs.caltech.edu/~wnoise/base2.html

via LifeLong Community

No comments:

Post a Comment