Help

May 04, 2005 1 Replies

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

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required