Bitwise operation - cocoder39/coco39_LC GitHub Wiki
- set a bit
num |= 1 << x;
- clear a bit
num &= ~(1 << x)
- toggle a bit
num ^= 1 << x
- check a bit
bit = (num >> x) & 1
- change the nth bit to x
num ^= (-x ^ number) & (1 << n)
- get the low bit
x & (-x)
(eg, 0b100100 -> 0b100, 0b101 -> 0b1)- x = 0b1, x & (-x) = 0b1
- x = 0b10, x & (-x) = 0b10
- x = 0b11, x & (-x) = 0b1
- 1680. Concatenation of Consecutive Binary Numbers