How to unset a specific bit in an integer
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Say, I have a integer like 10101 , I would like to unset the third bit to get 10001 ; if I have 10001 , I will still get 10001 ; how can I achieve it? unset(int i, int j) int i= 10101 or 10000 int j = 00100 回答1: Assuming that you are indexing bits from the right, this should work to unset a particular bit in value : int mask = 1 You can set the bit using similar code: value |= mask; where mask is as before. (This assumes that bit indexing starts at 0.) 回答2: To clear or unset a bit Use the bitwise AND operator (&) to clear a bit. number &= ~