25 lines
647 B
Python
25 lines
647 B
Python
import re
|
|
import sys
|
|
|
|
def binary_to_utf8(binary_string):
|
|
# padding = 8 - len(binary_string) % 8
|
|
# binary_string += '0' * padding
|
|
# binary_string = binary_string.rstrip('0')
|
|
|
|
bytes_list = [binary_string[i:i+8] for i in range(0, len(binary_string), 8)]
|
|
|
|
decimal_list = [int(byte, 2) for byte in bytes_list]
|
|
|
|
bytes = bytearray(decimal_list)
|
|
try:
|
|
utf8_text = bytes.decode('utf-8')
|
|
except UnicodeDecodeError:
|
|
utf8_text = bytes.decode('utf-8', errors='replace')
|
|
|
|
return utf8_text
|
|
|
|
return utf8_text
|
|
|
|
for line in sys.stdin:
|
|
result = binary_to_utf8(line.strip())
|
|
print(result.encode('utf-8')) |