Bit Flashcards
1
Q
Bit masking - turn nth bit on
A
a = a | (1 «_space;n)
2
Q
Bit masking - turn nth bit off
A
a = a & (~(1 «_space;n))
3
Q
Bit masking - toggle nth bit
A
a = a ^ (1 «_space;n)
4
Q
Bit masking - query nth bit (ask it’s true or false)
A
x = a & (1 «_space;n)
If x = 0, it’s off and vice verse