How to bitwise XOR of hex numbers in Python?

PythonProgrammingServer Side Programming

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.

raja
Published on 20-Apr-2018 08:34:06
Advertisements