Format ints into string of hex

前端 未结 10 1748
陌清茗
陌清茗 2020-11-30 08:16

I need to create a string of hex digits from a list of random integers (0-255). Each hex digit should be represented by two characters: 5 - \"05\", 16 - \"10\", etc.

10条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 09:10

    Similar to my other answer, except repeating the format string:

    >>> numbers = [1, 15, 255]
    >>> fmt = '{:02X}' * len(numbers)
    >>> fmt.format(*numbers)
    '010FFF'
    

提交回复
热议问题