Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
重複の可能性: 整数の特定のビットを設定解除する方法
次のような変数があるとします。
int n = 465;
最下位から 3 番目のビットをオフにするにはどうすればよいですか?
最下位から 3 番目のビットは (1<<2) です。オフにするには、それ以外のすべてのビットを 1 と AND します。
n &= ~(1 << 2)
(編集:ダンのコメントは正しいです、私の悪い:それは1 << 2であり、1 << 3ではありません)