Bitwise operation
Bitwise operation
Setting k-th bit of x: x |= 1 [shift] k
Clearing k-th bit: x &= ~(1 [shift] k)
Getting k-th bit: return (x [shift] k) & 1
Flipping k-th bit: x ^= 1 [shift] k (replaces 0 by 1, and 1 by 0.)
ex: 10311 - Goldbach and Euler
[via]
沒有留言:
張貼留言