Bitwise Exclusive OR (^)

The bitwise exclusive OR operator (^) sets each bit in the result to 1 if exactly one of the corresponding bits in its two operands is 1. In Fig. 20.8, lines 31–32 assign variables number1 and number2 the values 139 (00000000 00000000 00000000 10001011) and 199 (00000000 00000000 00000000 11000111), respectively. When these variables are combined with the bitwise exclusive OR operator in the expression number1 ^ number2 (line 37), the result is 00000000 00000000 00000000 01001100. Figure 20.10 summarizes the results of combining two bits with the bitwise exclusive OR operator.


Fig. 20.10. Combining two bits with the bitwise ...

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.