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.