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