From the OP...
To see if a bit is set or clear just requires the AND operator, but with no assignment. To see if bit 7 is set in the variable foo:
if(foo & 0x80) { }The condition will be zero if the bit is clear, and the condition will be non-zero if the bit is set. NOTE! The condition will be NON-ZERO when the bit is set. But the condition will not NECESSARILY BE ONE.
I'm having difficulty with this bit of code (no pun intended). I get the truth tables and most everything else where there is an assignment being made. What is making the "(foo & 0x80)" evaluate to a 1 or a 0? My entire understanding of bitwise operators is based on two bytes evaluating to a single byte. In the above code snippet two bytes are evaluating to a bit (boolean?). What if you had something instead like "(foo & 0x81)"? Would both bits need to evaluate to 1 in order for the if() statement to execute?