def toHex(num):
"""
:type num: int
:rtype: str
"""
chaDic = {: 'a', : 'b', : 'c', : 'd', : 'e', : 'f'}
hexStr = "" if num < :
num = num + ** while num >= :
digit = num %
hexStr = chaDic.get(digit, str(digit)) + hexStr
num //= 16
hexStr = chaDic.get(num, str(num)) + hexStr return hexStr print("转换前")
print()
a=toHex()
print("转换后")
print(a)
print("还原")
print(int(a,))
输出
bogon:Desktop macname$ python3 test.py
转换前 转换后 还原
参考:
https://blog.csdn.net/qiubingcsdn/article/details/83079235