C++ 按位运算符理解代码

C++ Bitwise Operator Understanding Code

a &= ~(1 << 10);

上面的代码实际上是指:

a &= (0 << 10);

~是按位取反(取每一个1变成0,每0变成1),所以如果你有x = 0b0100(一秒假设4位整数),那么~x == 0b1011<< 是 "shift this to the left",所以“(1 << 2) == 0b0100”。