-1

I have been trying to convert a hexadecimal string into a hexadecimal value in Python just as you can convert a string containing an integer into an integer value. I have tried the following

>>> a = '0x25'
>>> b = hex(a)
Traceback (most recent call last):
  File "<pyshell#47>", line 1, in <module>
    b=hex(a)
TypeError: hex() argument can't be converted to hex

and

 >>> b = '20'
 >>> int(b)
 20

but I haven't reached any viable solution.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

1 Answers1

0
In [1]: int('0x20', 0)
Out[1]: 32

In [2]: int('20', 16)
Out[2]: 32

https://docs.python.org/3/library/functions.html#int

user1238367
  • 505
  • 4
  • 11