c++ bitmask example
Example: bitmask c++
- Set ith bit: x|(1<<i)
1100 1100
| 0001 0000 (1<<i)
-----------
1101 1100
- Get ith bit: (x&(1<<i) != 0)
0010 1100
& 0010 0000 (1<<i)
------------
0010 0000 (is not zero)
- Clear ith bit: x&(~(1<<i))
~ : inverts
0011 0110
& 1101 1111 ~(1<<i)
-----------
0001 0110