Arduino and Bitwise, unexpected result

I'm a little confused.

I would like to check if a bit contains a bit (3 bits) a bit at a specific position.

if (B110 & B010 == B010)

(B110 is the number to check, B010 is the bit I want to see, if any)

The above code does not give me the expected result, both B110 are true and B101 is true. I'm sure I need to use & (and) to test with mask B010.

I understand that B110 and B010 will be equal to B010 and that B101 and B010 will be equal to B000. But is the if statement executed with two test bits?

I'm coding in Arduino, I'm sure this is a simple misunderstanding on my behalf, but I don’t know where.

+5
source share
2 answers

Try if ((B110 & B010) == B010)

if (B110 & (B010 == B010)), .

, == != , &, | .

+12

"== B010" . C, 0 "false", "". B110 & B010 ( ) B010, 0, .

+3

All Articles