Python 字符串与二进制串的相互转换

def encode(s):
    return ' '.join([bin(ord(c)).replace('0b', '') for c in s])
 
def decode(s):
    return ''.join([chr(i) for i in [int(b, 2) for b in s.split(' ')]])

  

posted @ 2019-06-27 15:37  程序猿凯  阅读(7722)  评论(0编辑  收藏  举报