Python XOR | Python Bitwise Operators

Python xor – In Python, XOR is a bitwise operator which is also known as Exclusive OR.
It is a logical operator which outputs 11 when any of the one operands is 11 (one is 11 and the other one is 00), but both are not 11, and not even 00.

The symbol for XOR in Python is ‘^’ and in maths, its symbol is ‘‘.

Bitwise XOR can be performed by using the “^” symbol. This operation can be used for different purposes; XOR of two integers, XOR of two Booleans,  or even Swapping two numbers using XOR, etc.

It can also be used using the operator module in python.

Truth Table –

A B AB
1 1 0
0 1 1
1 0 1
0 0 0

Code – 

a=15 

b=16

c=a^b

print(a,”XOR”,b,”=”,c)

OUTPUT

15 XOR 16 = 31

Tags: No tags

Add a Comment

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