I have a number 0x7fffffffd908(int representation) and I want it to align the length of machine address.
0x7fffffffd908 -> 0x00007fffffffd908
have any ways to achieve this only use format string?
I tried this :
"{:0>#18x}"
but result is 00000x7fffffffd908
.
CodePudding user response:
You can use the following format string
>>> "{0:#0{1}x}".format(0x7fffffffd908, 18)
0x00007fffffffd908
Which formats your value as hex, padded with leading 0
, to length 18.
CodePudding user response:
num = 140737488345352
print(f"{num:#018x}")