How to bitwise XOR of hex numbers in Python?


You can get the XOR of any type of numbers using the ^ operator. Specifically for hex numbers, you can use:

a = 0x12ef
b = 0xabcd
print(hex(a ^ b))

This will give the output:

0xb922

The 0x at the beginning of the numbers implies that the number is in hex representation. You can use the ^ operator for other integer representations as well.

Updated on: 17-Jun-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements