X and Y = 0000 1100
X | Y = 0011 1101
~ X = 1100 0011
X * Y = 0011 0001
We will now use these binary data to show the Bitwise operations used in the Python
>> Binary Right Shift
The value of the left operand is moved to the right based on
the number of bits determined by operand on the right.
X >> = 15 (which is 0000 1111)
<< Binary Left Shift
The value of the left operand is moved to the left based on
the number identified by the operand on the right.
X << 240 (which is 1111 0000)
& Binary AND
This operator copies and pastes a bit to the end result if it is
present in both operands.
(X and Y) which is 0000 1100)
^ Binary XOR
This operator duplicates a bit if it is present in one operand
but not on the other
(X ^ Y) = 49 (which is 0011 0001)
~ Complement of Binary Ones
This operator is unary and it can flip bits.
(~ X) = 61 (which is 1100 0011 in complement
of 2’s form because of a marked binary digit)
| Binary OR
This operator duplicates a bit if it is present in one of the
(X | Y) 61 (which is 0011 1101)