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;
如何关闭第三个最低有效位?
第三个最低有效位是 (1<<2)。要关闭,除此之外的所有位都为 1。
n &= ~(1 << 2)
(编辑:丹的评论是正确的,我的错:它是 1<<2,而不是 1<<3)