How do I convert hex to decimal in Python?

Sir D picture Sir D · Feb 9, 2012 · Viewed 338.6k times · Source

I have some Perl code where the hex() function converts hex data to decimal. How can I do it on Python?

Answer

Sven Marnach picture Sven Marnach · Feb 9, 2012

If by "hex data" you mean a string of the form

s = "6a48f82d8e828ce82b82"

you can use

i = int(s, 16)

to convert it to an integer and

str(i)

to convert it to a decimal string.