Bitwise Inclusive OR Operator (|)

The bitwise inclusive OR operator is used to set specific bits to 1 in an operand. In Fig. 20.8, line 22 assigns 15 (00000000 00000000 00000000 00001111) to variable number1, and line 23 assigns 241 (00000000 00000000 00000000 11110001) to variable setBits. When number1 and setBits are combined using the bitwise inclusive OR operator in the expression number1 | setBits (line 28), the result is 255 (00000000 00000000 00000000 11111111). Figure 20.9 summarizes the results of combining two bits with the bitwise inclusive-OR operator.

Image

Fig. 20.9. Combining two bits with the bitwise inclusive-OR operator (|).

Common ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.