Hallo, where I could find a complete manual (pdf) for programming in Ansi C?
I need to understand the meaning of operators like: |= ^= a & 0x07
Many Thanks Marco
Hallo, where I could find a complete manual (pdf) for programming in Ansi C?
I need to understand the meaning of operators like: |= ^= a & 0x07
Many Thanks Marco
Not sure, I'd recommend Google.
As to your immediate question, &, |, and ^ are bitwise operators, not to be confused with &&, ||, ^^, which are logical operators.
int A, B, C; C = A & B; /* bitwise and */ C = A | B; /* bitwise or */ C = A ^ B; /* bitwise xor */
The bitwise operators take two integers (run like hell if they're not integers), and perform an operation combining the high bit of A with the high bit of B, storing the result in the high bit of C, the next bit of A with the next bit of C into the next bit of C, and etc.
The logical operators take two boolean values ( 0 is FALSE, anything else is TRUE ) and compare them in the same way.
int A, B, C; C = A && B; /* set C true if A is true and B is true */ C = A || B; /* set C true if A is true or B is true */ C = A ^^ B; /* set C true if A is true xor B is true */
Your question as to |= and &= follow the C convention of allowing shorthand for assignment operators.
A &= 5; /* A = A & 5 */ A |= 5; /* A = A | 5 */ A += 5; /* A = A + 5 */
Hope this helps.
--Rob
ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.