The XOR operator is a binary operator—it requires 2 operands. An operand is a numeric argument to the operator (the numbers on each side of the "^" caret symbol).
Here We use a method (GetIntBinaryString) that shows us the bits that are set in each number.
And We see the bits set in the first operand, the second operand, and the result returned by the XOR operation.
Result The first 2 lines are the bits of the operands. The third line is the result from the "^" operator applied to those operands.
Tip In places where only one bit is set in both operands, the result value has that same bit set. Otherwise no bits were set.
static void Main()
// Demonstrate XOR for two integers.
int a = 5550 ^ 800
int b = 100 ^ 33
/// Returns binary representation string.
static string GetIntBinaryString
char b = new char;
int pos = 31;
int i = 0;
while (i < 32)
if ((n & (1 << i)) != 0)
b[pos] = '1';
b[pos] = '0';
return new string(b);