Python - how to convert int to string represent a 32bit Hex number
12,518
Try this:
'0x%08X' % 3652458
or (with Python 2.6 and newer)
'0x{0:08X}'.format(3652458)
both return:
'0x0037BB6A'
Author by
Admin
Updated on June 16, 2022Comments
-
Admin almost 2 years
I want to get a python solution for this problem:
e.g.
integer 1 -> string "0x00000001" integer 64 -> string "0x00000040" integer 3652458 -> string "0x0037BB6A"
The string size will not be change if number is in
range(0, 2**32)
. -
naeg over 12 yearsI'd like to give you another +1 for including
format
in your answer