#include <stdio.h>
int main() {
unsigned int a = 5; // Binary representation: 0000 0101
unsigned int b = 3; // Binary representation: 0000 0011
unsigned int result = a & b; // Bitwise AND operation
printf("a: %u\n", a);
printf("b: %u\n", b);
printf("result of a & b: %u\n", result);
return 0;
}
- Declare two unsigned integers
a
and b
with values 5 and 3, respectively. - Convert the decimal values of
a
and b
to binary representation: a
binary: 0000 0101b
binary: 0000 0011- Apply the bitwise AND operator (
&
) to each pair of corresponding bits: 0 & 0 = 0
0 & 0 = 0
0 & 0 = 0
0 & 1 = 0
1 & 0 = 0
0 & 1 = 0
1 & 0 = 0
1 & 1 = 1
- Combine the results of the bitwise AND operation to form the binary representation of the result:
- Result binary: 0000 0001
- Convert the binary representation of the result back to decimal:
- Result decimal: 1
- Print the values of
a
, b
, and the result of the bitwise AND operation.