The Bitwise AND Operator
When two values are ANDed, the binary representations of the values are compared bit by bit. Each corresponding bit that is a 1 in the first value and a 1 in the second value produce a 1 in the corresponding bit position of the result; anything else produces a 0. If b1 and b2 represent corresponding bits of the two operands, the following table, called a truth table, shows the result of b1 ANDed with b2 for all possible values of b1 and b2.
b1 b2 b1 & b2————————————————————————0 0 00 1 01 0 01 1 1
For example, if w1 and w2 are defined as short ints, and w1 is set equal to hexadecimal 15 and w2 is set equal to hexadecimal 0c, the following C statement assigns ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access