Bit Manipulation

1. Extract the last set bit

x & (-x)

eg.  x: 00110010

-x: 11001101 + 1 = 11001110

x & (-x) = 00000010

2. Remove the last set bit

x – x & (-x)

FacebookTwitterGoogle+Share

Leave a Reply

Your email address will not be published. Required fields are marked *