DESCRIPTION:
Write a function that takes in a binary string and returns the equivalent decoded text (the text is ASCII encoded).
Each 8 bits on the binary string represent 1 character on the ASCII table.
The input string will always be a valid binary string.
Characters can be in the range from "00000000" to "11111111" (inclusive)
Note: In the case of an empty binary string your function should return an empty string.
def binary_to_string(binary):
alist=[]
ans=""
for i in range(int(len(binary)/8)):
ans+=chr(int(binary[8*i:8*(i+1)],2))
return ans
'알고리즘 문제 > CodeWar' 카테고리의 다른 글
Remove the Parentheses (0) | 2022.11.10 |
---|---|
Simple Frequency Sort (0) | 2022.11.10 |
Square Matrix Multiplication (0) | 2022.11.08 |
Twisted Sum (0) | 2022.11.08 |
Number Zoo Patrol (0) | 2022.11.07 |