Checking if bit is not set

前端 未结 4 1035
挽巷
挽巷 2020-12-31 07:30

If I use this: if(value & 4) to check if the bit is set, then how do I check if the bit isn\'t set?

I tried with if(!value & 4) or

4条回答
  •  醉梦人生
    2020-12-31 07:40

    You could do it many ways, but the easiest (easiest as in requires the least amount of thought) would be just negate the entire expression you already have:

    if (!(value & 4))
    

提交回复
热议问题