Checking if bit is not set

前端 未结 4 1072
挽巷
挽巷 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:45

    Simply:

    if ((value & 4) == 0)
    

    Why?

    If value is 01110011

    Then

    01110011
    &
    00000100
    --------
    

    Will return 0 because 4th bit is off.

提交回复
热议问题