Explain the Bitwise-Inclusive-OR Operator: |?
The bitwise-inclusive-OR operator (|) contrast each bit of its first operand to the corresponding bit of its second operand and if either bit is 1 the corresponding result bit is set to 1 Or else the corresponding result bit is set to 0.
x
|
Y
|
x | y
|
0
|
0
|
0
|
0
|
1
|
1
|
1
|
0
|
1
|
1
|
1
|
1
|
In the following instance the bitwise-inclusive-OR operator (|) compares the bits of two integers nNumA
and nNumB
:
// Example of the bitwise-inclusive-OR operator
int nNumA=9, nNumB=3, nNumC; // 00001001, 00000011
nNumC = nNumA | nNumB; // nNumC is now 11: 00001011