-1
num="1F"
nm="1"
nm1="2"
hex(num)^hex(nm)^hex(nm1)

I wrote it like the code above, but hex doesn't work properly.

I want to convert the string to hexadecimal, and I want an xor operation of the converted value.

What should I do?

huntersang
  • 11
  • 4
  • 1
    "hex" does the opposite. Use "int(num, 16)". – Michael Butscher Nov 27 '22 at 08:33
  • You want to interpret the string as hexadecimal number. It’s already hexadecimal, you don’t need to convert it to hexadecimal. – deceze Nov 27 '22 at 08:38
  • Does this answer your question? [Convert hex string to integer in Python](https://stackoverflow.com/questions/209513/convert-hex-string-to-integer-in-python) – Sören Nov 27 '22 at 10:44

1 Answers1

0

The variable num can be converted to int using int(num, 16). Other variables nm, nm1 are just integers in form of strings. to convert them use int(nm), int(nm1)

num = "1F"
nm = "1"
nm1 = "2"

result = int(num, 16) ^ int(nm) ^ int(nm1)
print(result)

> 28