How to convert an int to a hex string?

后端 未结 13 746
不知归路
不知归路 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:38

    Also you can convert any number in any base to hex. Use this one line code here it's easy and simple to use:

    hex(int(n,x)).replace("0x","")

    You have a string n that is your number and x the base of that number. First, change it to integer and then to hex but hex has 0x at the first of it so with replace we remove it.

提交回复
热议问题