& is a “bitwise and” operator. Think of it converting the two numbers to binary, then wherever the two numbers both have a “1” in the same place, keeps the “1”, otherwise clears it to “0”.
7 & 2 returns a 2 (00000111 & 00000010 returns a 00000010)
| is a “bitwise or” operator – if either bit has a 1 it returns a 1. If both bits are 0 it returns a 0.
^ is a “bitwise exclusive OR” (sometimes known as XOR). Returns a 1 if either number has a 1 but not both, otherwise a 0.
~ is “bitwise NOT” (one’s complement). Returns the opposite number (1 to 0, 0 to 1).
Note they all operate on the bits (as in binary numbers).
There used to be more combinations in BASIC’s wild days (when Basic was BASIC), but I guess C isn’t as wild.
Do not confuse & and &&, and | and ||. The latter symbols apply to the whole number, not to the bits.
<< shifts each bit to the left (sort of like multiplying by 2 each time). >> shifts each bit to the right (dividing by 2 each time). In your case X<<7 shifts all the bits in X to the left by 7: 0000.0001 to 1.0000.0000 (I put in decimal points to make it clearer). You’ll have to find out what p3_aux produces in the lowest bit, then all the other bits are cleared, it then shifts it left 7 bits.
X?0:1 I think evaluates X, then returns a 0 if true, or 1 if false. It’s a shorthand if statement. So after doing the above, it is evaulated true (1), it returns a zero, else if it is false (0) it returns a one, and is put into p3_sw_5. (a true might be from any non-zero value, and false is always zero.)
I don’t know offhand the precidence of which does what first. I am assuming it is ((p3_aux & 1) << 7), not (p3_aux & (1 << 7)), but looking again I can’t tell and I don’t remember.
Find yourself a book on C – it’s all in there!
Roger.
Always do right! This will gratify some people and astonish the rest. - Mark Twain