Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I want to convert string 1F to hex 1F in Python, what should I do?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading