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)
.
Python hex() function is used to convert an integer to a lowercase hexadecimal string prefixed with “0x”. We can also pass an object to hex() function, in that case the object must have __index__() function defined that returns integer. The input integer argument can be in any base such as binary, octal etc.
In Python an integer can be converted into a string using the built-in str() function. The str() function takes in any python data type and converts it into a string.
toHexString() method in Java converts Integer to hex string. Let's say the following are our integer values. int val1 = 5; int val2 = 7; int val3 = 13; Convert the above int values to hex string.
When denoting hexadecimal numbers in Python, prefix the numbers with '0x'.
Try this:
'0x%08X' % 3652458
or (with Python 2.6 and newer)
'0x{0:08X}'.format(3652458)
both return:
'0x0037BB6A'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With