Page 152 - Cs_withBlue_J_C11_Flipbook
P. 152
To work with Bitwise Operators, we need to make a truth table. A truth table is a tabular representation that displays
the input and output bits using bitwise operators like &, | and !. We represent the output in the truth table as true
(1) or false (0), however, the computer means it actually as high or low, which basically means ON or OFF respectively.
Let us see in detail.
a. Bitwise AND (&): When both the results are true, this operator returns true.
nd
st
st
1 Bit 2 Bit 1 Bit & 2 Bit
nd
0 0 0
0 1 0
1 0 0
1 1 1
b. Bitwise OR (|): When both the results are false, this operator returns false else it returns true.
1 Bit 2 Bit 1 Bit | 2 Bit
st
nd
nd
st
0 0 0
0 1 1
1 0 1
1 1 1
c. Bitwise Not(!): This operator works on one operand only and it returns the reverse of the output. That is, it negates
the result.
1 Bit !(1 Bit)
st
st
0 1
1 0
d. Bitwise XOR(^) : This operator results in false if the operands are of the same value.
nd
st
nd
st
1 Bit 2 Bit 1 Bit ^ 2 Bit
0 0 0
0 1 1
1 0 1
1 1 0
Some Solved Examples:
1. 6 & 3
First, we have to convert the given digits into their equivalent binary values.
6 = 0110 (In Binary)
3 = 0011 (In Binary)
Bit Operation of 6 & 3
0110
& 0011
0010 which is 2 in decimal
Ans. 2
150150 Touchpad Computer Science-XI

