The use of the xor operator ^ in C++
- 2020-04-01 23:28:52
- OfStack
The ^ operation in C++ represents a binary xor operation
2 ^ 4 = 6
010 ^ 100 = 110
This operation can be used to convert two Numbers without intermediate variables
The following example implements the substitution of a and b
A = 2;
B = 4;
A = a ^ b;
B = a ^ b;
A = a ^ b;
Xor ^ is a very important operator, and a large number of problems can be solved by using xor, especially in the interview questions of major companies. Xor is definitely a key operator.