Arduino and Bitwise, unexpected result?

Try if ((B110 & B010) == B010) At the moment it's running as if (B110 & (B010 == B010)) which will always be true. As this table shows, == and! = have a higher precedence than &, | etc.

Yes, exactly what I was about to say, I can only add that it's completely insane of C's designers that theu didn't make & stronger than ==, forcing us to litter our code with enough parentheses to make it look like lisp. – dren. Dk Jun 21 at 12:04 @dren Absolutely ;) As a general rule of thumb, if I'm doing a calculation in an IF I always put the calculation in parentheses of their own.

– Majenko Jun 21 at 12:26 1 If there's ever any doubt, I use extra parens. I don't know the precedence of operators, but I do know that the compiler will obey parens. – blalor Jun 21 at 12:59 Thanks adding the parentheses works fine.

I didn't know the precedence of operators that far down. – Ashley Hughes Jun 21 at 20:39.

The "== B010" is actually unnecessary in this test. In C, 0 represents "false," while any nonzero value is considered "true. " B110 & B010 (or any other value with that bit set) will return B010, which is not equal to 0, so the test succeeds.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions