Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
79 views
in Technique[技术] by (71.8m points)

python - How do I make a text to binary?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Text to binary convert :

name = "Name"
binary = ' '.join(format(ord(x), 'b') for x in name)

Binary to Text :

binary = '100001'

binary_values = binary.split()

ascii_string = ""
for binary_value in binary_values:
    an_integer = int(binary_value, 2)

    ascii_character = chr(an_integer)

    ascii_string += ascii_character

print(ascii_string)

Here is my git repo


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...