Is this documented...anywhere?

An observation...

This works....

if (x+y == z) { stuff.....

BUT THIS DOES NOT... though one might think so.

if ( x & y == z) { stuff...

AND THIS DOES.... when I finally worked out why things didn't work!

if (( x & y) == z) { stuff...

I couldn't find any reference to this trap anywhere. Or have I missed it?

Is this just a newby trap, or should it be blindingly obvious?

regards in advance ... leolfs

http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Operator_precedence

A C++, or even C book, might be handy.

rFree, I guess this is what you mean.

]"The precedence of the bitwise logical operators has been criticized.[1] Conceptually, & and | are arithmetic operators like + and *. The expression a & b == 7 is syntactically parsed as a & (b == 7) whereas the expression a + b == 7 is parsed as (a + b) == 7. This requires parentheses to be used more often than they otherwise would."

Thanks for putting me in the picture. I wouldn't have known where to look. I was kind of hoping the Arduino environment didn't allow pitfalls like this. Still that's what such a good forum is for. Info gained, problem solved.

PS A compendium of odd things for beginners to watch out for would be a good idea.Like "when masking for a bit, don't do it like this because..."

In general: It is hard to have too many brackets!

You can use them to eliminate the possiblity of "order of operations" bugs.

=== P.S.... but easy to have too few ohs! Apologies for the earlier typo. The post used to say "...hard to have to many brackets"

(a + b) == 7 no problem