Hi read this in a book. What does this symbol mean the vertical line and the equals sign?
|=
Printable View
Hi read this in a book. What does this symbol mean the vertical line and the equals sign?
|=
| is bitwise OR
|= means you're setting a bit..i think
It's very much like +=
Only it's bitwise-or rather than addition.
Look up assignment operators.
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...
It gets into binary logic which isn't really used in programming for general purpose things, but when working with I/O ports (etc) at the bit level it can be helpful.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;
Awesome answers!!!!! Thanks :D