Table of Contents
The bitwise AND operator & performs an AND operation on each corresponding bit of two integer operands. A bit in the result is 1 only when both corresponding bits are 1.
#include <stdio.h>
int main()
{
int a = 12;
int b = 10;
printf("a & b = %d\n", a & b);
return 0;
}
Example Output #
a & b = 8
Explanation #
The values are represented in binary as:
12 = 1100
10 = 1010
----
1000
The & operator compares each pair of corresponding bits:
| a | b | a & b |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
Therefore:
a & b
produces binary 1000, which is decimal 8.
The bitwise AND operator operates on the individual bits of integer operands.