Bit manipulation 使用 AND、OR、XOR、NOT 和移位直接对整数的二进制表示进行操作。它实现了紧凑、无分支和超快速的运算。
Core operations
python
x & 1 # is x odd? (lowest bit)
x << 1 # multiply by 2
x >> 1 # integer divide by 2
x & (1 << k) # is bit k set?
x | (1 << k) # set bit k
x & ~( << k)
x ^ ( << k)
