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 ...

Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.