Understanding bitwise truth tables of an operator is crucial. Consider the following: where A and B are inputs and Y is an output.
& (Bitwise AND) When inputs A and B are true, the output is true; otherwise the conclusion will be false
ABY --------- 0 | 0 | 0 0 | 1 | 0 1 | 0 | 0 1 | 1 | 1
| (Bitwise or) When A or B or both inputs are true, true; otherwise the conclusion will be false
ABY --------- 0 | 0 | 0 0 | 1 | 1 1 | 0 | 1 1 | 1 | 1
^ (Bitwise X-Or) When A and B are opposite states, the output is true; otherwise the conclusion will be false
ABY --------- 0 | 0 | 0 0 | 1 | 1 1 | 0 | 1 1 | 1 | 0
! (Bitwise Deviation) An output is the opposite state of an input.
AY ----- 0 | 1 1 | 0
Your equation (5 and 4) == (0101 and 0100) == 0100 == 4 == true
0101 & 0100 ------ 0100
Fiddling bits
source share