views:

130

answers:

3

How to convert

x = "0x000000001" # hex number string

to

y = "1"
+3  A: 

Use int() and provide the base which your number is in (in your case 16).
Then apply str() to convert it back to a string:

y = str(int(x, 16))

Note: If you omit the base then the default base 10 is used which would result in a ValueError in your case.

Felix Kling
+12  A: 

You can do:

y = int("0x000000001", 16)

in your case:

y = int(x, 16)

Looks like you want the int converted to string:

y = str(int(x, 16))
codaddict
+2  A: 
>>> int("0x000000001", 16)
1
SilentGhost