9 Bit Manipulation 常用公式
数1的数目:L365 Count 1 in Binary
Set Union:
Set intersection:
Set Subtraction:
Set negation:
Set bit
Clear bit
Test bit
Find right most bit = 1
Clear the least bit = 1
check if num is 2's power or num == 0
Rotate right shift:
Rotate left shift is similar:
Swap bits in integer
x ^ 0s = x | x & 0s = 0 | x | 0s = x |
x ^ 1s = ~x | x & 1s = x | x | 1s = 1s |
x ^ x = 0 | x & x = x | x | x = x |
swap number with xor
swap number with math
Last updated