Bitwise operations

Bitwise operations can apply to the binary data type but also integers.

Representation of integers in Python Index In python integers are unsigned and stored using Two's complement.

The operations in python are as follows (applied to x = 11 or 0000 1011 and y = 6 or 0000 0110)

OperationMeaningExample
&Bitwise ANDx & y = 4 0000 0010
|Bitwise ORx | y = 15 0000 1111
~Bitwise NOT~ x = -12 1111 0100
^Bitwise XORx ^ y = 13 0000 1101
>>Bitwise right shiftx >> 2 = 2 0000 0010
<<Bitwise left shiftx << 2 = 44 0010 1100