python – Format ints into string of hex

python – Format ints into string of hex

Just for completeness, using the modern .format() syntax:

>>> numbers = [1, 15, 255]
>>> .join({:02X}.format(a) for a in numbers)
010FFF
.join(%02x%i for i in input)

python – Format ints into string of hex

Python 2:

>>> str(bytearray([0,1,2,3,127,200,255])).encode(hex)
000102037fc8ff

Python 3:

>>> bytearray([0,1,2,3,127,200,255]).hex()
000102037fc8ff

Leave a Reply

Your email address will not be published. Required fields are marked *