Heres a test program:
Code:
#include <stdio.h>
int main()
{
unsigned char reg = 128;
char val = 6;
reg |= val & 128;
printf("%02x\n", reg);
return 0;
}
I am trying to clear the 7th bit of reg (has bits 0-7). I use 6 as an example... It doesnt matter since the 7th bit of 6 is 0 anyway. It doesn't clear, it still stays as 128 (should now be 0)
Heres what does work though... (This is important)... If the 7th bit of val is 1, then obviously reg's 7th bit needs to be 1 as well. "| val & 128" handles this fine. Can anyone assist me with this? I have made a truth table as well:
Code:
reg val output
0 1 1
1 0 0
0 0 0
1 1 1
Note, I am trying to do this all in one line if possible.
Is it possible?