python进制转换

本小妞迷上赌 提交于 2019-11-28 18:46:51

代码源于网络:

十六进制转ascii与ascii转十六进制

#!/usr/bin/python
# -*- coding: UTF-8 -*-

class Converter(object):
    def to_ascii(h):
        list_s = []
        for i in range(0,len(h),2):
            list_s.append(chr(int(h[i:i+2],16)))
        return ''.join(list_s)
    def to_hex(s):
        list_h = []
        for c in s:
            list_h.append(str(hex(ord(c))[2:]))
        return ''.join(list_h)

print(Converter.to_hex("hello world!"))
print(Converter.to_ascii("68656c6c6f20776f726c6421"))

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!