Define the Bitwise-Exclusive-OR Operator: ^:
The bitwise-exclusive-OR operator (^) compares every bit of its first operand to the corresponding bit of its second operand. If one bit is 1and the other bit is 0, the corresponding result bit is set to 1. Or else, the corresponding result bit is set to 0.
x
|
Y
|
x ^ y
|
0
|
0
|
0
|
0
|
1
|
1
|
1
|
0
|
1
|
1
|
1
|
0
|
In the following instance 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