-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.

0

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.