The output of the code might not be as clear as the outputs we’ve been looking at throughout this chapter. Let’s break down what the operators are doing one step at a time.
A & B
The operator will first convert each decimal operand into its binary form.
12 in binary form is
0000
0000
1100
1100
5 in binary form is
0000
0000
0101
0101
From there, it will apply the above rules for the binary AND operator (&) on each pair of bits, i.e. the first bit of 12 with the first bit of 5 and so on.
And that is how A & B will yield a result of 4.
Try to map the rules onto the other operations and see if you get the same result as the output above.
That sums up bitwise operators. Let’s move on to our final type of operator, assignment operator, in the next lesson.