How do I convert hex to decimal in Python? [duplicate]
You could use a literal eval:
>>> ast.literal_eval('0xdeadbeef')3735928559
Or just specify the base as argument to int
:
>>> int('deadbeef', 16)3735928559
A trick that is not well known, if you specify the base 0
to int
, then Python will attempt to determine the base from the string prefix:
>>> int("0xff", 0)255>>> int("0o644", 0)420>>> int("0b100", 0)4>>> int("100", 0)100