I'm having some problems testing bit 0 of a variable to see if it's a 1. Here's the snippet of the code:
if ((bWork && 0x01)==1) bTemp = bTemp|0x01; else bTemp = bTemp & 0xFE;
"You learn something new everyday." Looking at your original post, you probably also want to check out the |= and &= operators in your 'C' text book (and += etc).
Thanks. And thanks for the tip on the if .. then statement Jon. You learn something new everyday.
&& is logical and. & is bitwise and. The given snippet will take the if path whenever bWork is "true" (non-zero). (The other operand, "0x01", is always true, so it only depends on bWork.) You probably want:
if ((bWork & 0x01) == 1)
You are using a logical AND instead of a bitwise AND. The following code does what you want:
if ((bWork & 0x01)==1) bTemp = bTemp|0x01; else bTemp = bTemp & 0xFE;
bTemp ^= (bWork & 0x01);
View all questions in Keil forum