Bit Hacks Flashcards
1
Q
x AND 0’s
A
0
2
Q
x AND 1’s
A
x
3
Q
x AND x
A
x
4
Q
x OR 0’s
A
x
5
Q
x OR 1’s
A
1’s
6
Q
x OR x
A
x
7
Q
x XOR 0’s
A
x
8
Q
x XOR 1’s
A
~x
9
Q
x XOR x
A
0’s
10
Q
checking if the kth bit is set
A
n AND (1
11
Q
setting the kth bit
A
n OR (1
12
Q
clearing the kth bit
A
n AND ~(1
13
Q
toggling kth bit
A
n XOR (1
14
Q
toggling rightmost one bit
A
n AND n-1
15
Q
isolating rightmost one bit
A
n AND -n