The Bitwise Inclusive-OR Operator
When two values are bitwise inclusive-ORed in Objective-C, the binary representation of the two values is once again compared bit by bit. This time, each bit that is a 1 in the first value or a 1 in the second value produces a 1 in the corresponding bit of the result. The truth table for the inclusive-OR operator is shown next.
b1 b2 b1 | b2————————————————————————0 0 00 1 11 0 11 1 1
So if w1 is a short int equal to hexadecimal 19 and w2 is a short int equal to hexadecimal 6a, a bitwise inclusive-OR of w1 and w2 produces a result of hexadecimal 7b, as shown:
w1 0000 0000 0001 1001 0x19w2 0000 0000 0110 1010 | 0x6a————————————————————————————————————— ...
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