# Python bitwise operators

Python Bitwise operators are used to compare (binary) numbers. Python’s bitwise operators only work with integers.

The values are first converted to binary, and then manipulations are done bit by bit, hence the phrase “bitwise operators.” The outcome is then displayed in decimal numbers.

Every binary bitwise operator has a compound operator that performs an enhanced application.

## Python bitwise operators

Simple example code.

``````a = 60  # 60 = 0011 1100
b = 13  # 13 = 0000 1101
c = 0

c = a & b  # 12 = 0000 1100
print("& Value of c is ", c)

c = a | b  # 61 = 0011 1101
print("| Value of c is ", c)

c = a ^ b  # 49 = 0011 0001
print("^ Value of c is ", c)

c = ~a  # -61 = 1100 0011
print("~ Value of c is ", c)

c = a << 2  # 240 = 1111 0000
print("<< Value of c is ", c)

c = a >> 2  # 15 = 0000 1111
print(">> Value of c is ", c)
``````

Output:

Do comment if you have any doubts or suggestions on this Python operator topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.