So I have been trying to make a text to binary converter but what I do is I convert every single letter and symbol to the binary equivalent but as you can imagine this takes long and i'm wondering if there is a shorter way to do this.
Asked
Active
Viewed 292 times
3 Answers
0
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
0
This programm convert text to binaries list :
a_string = "abc"
a_byte_array = bytearray(a_string, "utf8") #Create bytearray
byte_list = []
for byte in a_byte_array:
binary_representation = bin(byte) #Convert to binary
byte_list.append(binary_representation) #Add to list
print(byte_list)

Roma1n
- 29
- 1
- 5