Skip to content

Python XOR int

  • by

Use ^ operator in Python to get XOR int. As XOR is a bitwise operator, it will compare bits of both integers bit by bit after converting them into binary numbers.

The truth table for XOR (binary)


Python XOR int

Simple example code.

# Initializing two integers a and b
a = 10
b = 30

# Finding XOR of a and b using ^ operator
c = a ^ b

# Printing the XOR value
print(a, "XOR", b, "=", c)


Python XOR int

XOR(a,b) for integers

def XOR(a,b):
    return a ^ b

nbr1 = 67
nbr2 = 73
print (XOR(nbr1, nbr2))

Do comment if you have any doubts or suggestions on this Python xor 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.

Leave a Reply

Your email address will not be published. Required fields are marked *