-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryToText.py
More file actions
17 lines (15 loc) · 823 Bytes
/
Copy pathBinaryToText.py
File metadata and controls
17 lines (15 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def binary_to_text(n):
"""
Create a function that takes a binary string and returns the text. The eight bits on the binary string represent 1 character on the ASCII table. For further info, check out the resource tab.
Examples
binary_to_text("01101110011011110110010001100101") ➞ "node"
binary_to_text('0111001001100101011000010110001101110100') ➞ "react"
binary_to_text("011100000111100101110100011010000110111101101110") ➞ "python"
Notes
Inputs are all valid strings.
"""
return ''.join(chr(int(n[i:i+8],2)) for i in range(0,len(n),8))
if __name__ == "__main__":
print(binary_to_text("01101110011011110110010001100101"))
print(binary_to_text('0111001001100101011000010110001101110100'))
print(binary_to_text("011100000111100101110100011010000110111101101110"))