Important: The C bit operators act on integers!
They are called bit operators because they act on each pair of bits at the same position of the two integers operands.
Bit operation (at each bit position) |
C Notation |
---|---|
AND | a & b |
OR | a | b |
XOR | a ^ b |
Not | ~a |
Examples (for 4 bit integers)
x | 1011 |
y | 0101 |
x | y | 1111 |
x | 1011 |
y | 0101 |
x & y | 0001 |
x | 1011 |
y | 0101 |
x ^ y | 1110 |
x | 1011 |
~x | 0100 |