How to convert an int to a hex string?

后端 未结 13 745
不知归路
不知归路 2020-11-28 03:27

I want to take an integer (that will be <= 255), to a hex string representation

e.g.: I want to pass in 65 and get out \'\\x41\', or

13条回答
  •  独厮守ぢ
    2020-11-28 03:41

    What about hex()?

    hex(255)  # 0xff
    

    If you really want to have \ in front you can do:

    print '\\' + hex(255)[1:]
    

提交回复
热议问题