Introduction to the xor operator of c
- 2020-05-24 06:02:09
- OfStack
int a = 5;
int b = 30;
Console.WriteLine(a^b);
Console.ReadKey();
The output is 27
That's because the base 2 of 5 is 2
0000 0101
The base 2 of 30 is zero
0001 1110
And the difference or algorithm is, you compare each bit of two base two Numbers, if they're the same, they're 0, if they're different, they're 1. Therefore, it should be listed as follows:
0000 0101
0001 1110
--------------
0001 1011
So you get 0001, 1011. And this base two is going to be 27.