Format ints into string of hex

前端 未结 10 1743
陌清茗
陌清茗 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:12

    a = [0,1,2,3,127,200,255]
    print str.join("", ("%02x" % i for i in a))
    

    prints

    000102037fc8ff
    

    (Also note that your code will fail for integers in the range from 10 to 15.)

提交回复
热议问题