bitwise operators in C
note that when you bitwise and (or, xor), each bit is anded (ored, xored) with the correspoding bit in the other word.
so 0b1010 & 0b1100 becomes 0b1000
or in hex 0xA & 0xC becomes 0x8
and is great for masking/clearing bits - say you want to zero all but the last three bits in a byte, call it val.
val = val & 0x7;
or is good for setting bits. for example, setting pins to input (1) or output (0):
TRISB = TRISB | 0b00011100; // sets pins 2, 3 & 4 to input, leave the others alone
I prefer to use binary repersentation when fiddling with bits in registers. makes it alot clear what's going on.
Phil