python实现字符串与二进制相互转换

#Convert a string to a binary
def encode(Target_string):
return ’ ‘.join([bin(ord©).replace(‘0b’, ‘’) for c in Target_string])
#Convert binary to string
def decode(Target_binary):
return ‘’.join([chr(i) for i in [int(b, 2) for b in Target_binary.split(’ ')]])

你可能感兴趣的:(python实现字符串与二进制相互转换)