Bitwise XOR Operator (^)


Bitwise XOR Operator

Bitwise XOR Operator is used to perform XOR operation between two given operands at bit level.

Symbol

The symbol of bitwise XOR operator is ^.

Syntax

The syntax to do bitwise XOR operation between the operands: x and y is

x ^ y

Example

The following is a simple example of how bitwise XOR operation is done between two numbers.

x = 5
y = 20

#bit level
    x = 00000101
    y = 00010100
x ^ y = 00010001

Therefore x ^ y = 17

In this following program, we take integer values in x, and y, and perform bitwise XOR operation between them.

Python Program

x = 5
y = 20
output = x ^ y
print(f'{x} ^ {y} = {output}')

Output

5 ^ 20 = 17

Summary

In this tutorial of Python Examples, we learned about Bitwise XOR Operator, and it's usage with the help of examples.