A little record of the XOR operation of java bit operations

First of all, the XOR operation is that the numbers on each bit are different to 1, and the same is 0.

Second, XORing the values ​​of two numeric variables three times is equivalent to swapping the values ​​of the two variables.

E.g:

int a = 4;
int b = 10;

a = a ^ b;
b = b ^ a;
a = a ^ b;

The result after that is:

进行位异或运算
a: 10
b: 4

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325290062&siteId=291194637