In the sketch I'm working on, I'm storing several 1-bit values representing different boolean states in a single byte, trying to save precious RAM.
(example for 5 boolean states: dec10
= b00001010
, the five states are 0
, 1
, 0
, 1
, 0
)
I'm then using an if
statement to determine if the relevant bit is TRUE
or FALSE
:
if ((options>>3) & 1 == 1)
The above will evaluate true
when the relevant bit is 1
, so if I want to carry out something in that case, great, no problem!
However, if I want my if
statement to evaluate TRUE
in the event that the relevant bit is 0
, I can't work out what code I need.
I thought the problem might be that the other 'non-relevant' bits were interfering, so I tried bit shifting the LSB all the way to MSB position and then shifting back to LSB:
if ((options<<4>>7) & 1 == 0)
but this still isn't doing what I'm trying to achieve (and seems like a lot of work for the processor).
It also feels like I've tried just about every combination of ~&0
, !&0
, ==0
, !=0
, ~&1
, !&1
, ==1
, !=1
there is, but I must have missed something...
Can anyone tell me how I get an if statement to evaluate true in the event that the bit is a zero?
if ((options>>3) & 1 == 0)
orif ((options>>3) & 1 != 1)
- if neither of them work, you did something wrong