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(’ ')]])

猜你喜欢

转载自blog.csdn.net/martinnnu/article/details/84030259
今日推荐