Set the i-th bit to zero? [duplicate]
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: How do you set, clear, and toggle a single bit? 26 answers I would like to set the i-th bit to zero no matter what the i-th bit is. unsigned char pt = 0b01100001; pt[0] = 0; // its not how we do this... Setting it to one, we can use a mask pt | (1 << i) but i'm not sure how to create a mask for setting 0, if thats possible. 回答1: You just have to replace the logical OR with a logical AND operation. You would use the & operator for that: pt = pt & ~(1 << i); You have to invert your mask because logical