I have the following hex number 0x00000000004087b8 and I have to convert this to 0x4087b8 so I would be able to append it to my list. Does anyone have any Idea how can I do this conversion in python?
Asked
Active
Viewed 567 times
-1
-
Could be [this kind of thing?](https://stackoverflow.com/questions/13142347/how-to-remove-leading-and-trailing-zeros-in-a-string-python) – neophlegm Dec 14 '17 at 22:42
-
I would assume that wouldn't work since strip would remove the 0 before the x too. She'd have to split it first and then lstrip it instead. – Saravana Kumar Dec 14 '17 at 22:43
-
1what is "0x00000000004087b8 "?? A string? – juanpa.arrivillaga Dec 14 '17 at 22:45
-
You realize the two hex numbers in your questions have different values on a 64 bit machine? Is stripping away the prefix zero's to go to different architectures (e.g. 64 to 32 or...)? – Frank C. Oct 18 '18 at 21:38
2 Answers
4
I assume that you have a string, I will recommend doing it like that :
fixed_address = hex(int(address, 16))

Idanushka
- 340
- 2
- 10
3
Maybe something like this would work?
hex_num = "0x00000000004087b8"
hex_num = "0x{}".format(hex.split('x')[1].lstrip('0'))

Saravana Kumar
- 482
- 3
- 10
-
Thanks for pointing that out. Forgot the quotes. My bad. Try now. – Saravana Kumar Dec 14 '17 at 22:50