Bitwise-Exclusive-OR Operator: ^
exclusive-OR-expression :
AND-expression
exclusive-OR-expression **^**AND-expression
The bitwise-exclusive-OR operator (^) compares each bit of its first operand to the corresponding bit of its second operand. If one bit is 0 and the other bit is 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0.
Example
In the following example, the bitwise-exclusive-OR operator (^) compares the bits of two integers, nNumA
and nNumB
:
// Example of the bitwise-exclusive-OR operator
int nNumA=9, nNumB=3, nNumC; // 00001001, 00000011
nNumC = nNumA ^ nNumB; // nNumC is now 10: 00001010
For related information, see bitwise-AND, bitwise-inclusive-OR, shift operators, and one's complement.