位运算 (学习记录)
void myswap(int &a, int&b){
if (a!=b){
a ^= b;
b ^= a;
a ^= b;
}
}
假设:a=5;b=10
a=0000 0000 0000 0101
b=0000 0000 0000 1010
a = a ^ a =0000 0000 0000 0000
b = b ^ b =0000 0000 0000 0000
b = b ^ a = b ^ a ^ b = b ^ b ^ a = 0000 0000 0000 0101 = 5
a = a ^ a = a ^ a ^ b = 0000 0000 0000 1010 = 10