清理一下

C 風格的位操作

可以使用按位 AND 運算子(&)清除一個位。

// Bit x will be cleared
number &= ~(1LL << x);

使用 std::bitset

reset(x)set(x,false) - 清除位置 x 的位。

std::bitset<5> num(std::string("01100"));
num.reset(2);     // num is now 01000
num.reset(0);     // num is still 01000
num.set(3,false); // num is now 00000