Hi read this in a book. What does this symbol mean the vertical line and the equals sign?

|=

Printable View

- 01-20-2011shrink_tubingCOnfused about the |= symbol?
Hi read this in a book. What does this symbol mean the vertical line and the equals sign?

|= - 01-20-2011Eman
| is bitwise OR

|= means you're setting a bit..i think - 01-20-2011Salem
It's very much like +=

Only it's bitwise-or rather than addition.

Look up assignment operators. - 01-20-2011CommonTater
It's a shorthand version of : x = x | y;

It does a bitwise OR...

The logic "truth table" is like this...

0 OR 0 = 0

1 OR 0 = 1

0 OR 1 = 1

1 OR 1 = 1

and it's done on every bit of the variable...

That is to say that the two numbers are compared at the binary level and all the 1 bits are merged, like this...

Code:

char a = 3; // in binary 00000011

char b = 24; // in binary 00011000

a |= b; // in binary 00011011

Printf("%d",a); // should display 27;

char a = 27; // in binary 00011011

char b = 24; // in binary 00011000

a |= b; // in binary 00011011

Printf("%d",a); // should still display 27;

- 01-20-2011shrink_tubing
Awesome answers!!!!! Thanks :D