How to convert hex string into int in Python?

PythonServer Side ProgrammingProgramming

Hex strings generally have a "0x" prefix. If you have this prefix and a valid string, you can use int(string, 0) to get the integer. The 0 is provided to tell the function to automatically interpret the base from prefix. For example:

>>> int("0xfe43", 0)

If you don't have a "0x" prefix, you can pass 16 instead of 0 to specify the base of the number. For example:

>>> int("fe43", 16)
Published on 13-Dec-2017 07:31:53