diff --git a/.idea/djfz-2023.iml b/.idea/djfz-2023.iml index 8388dbc..9b31378 100644 --- a/.idea/djfz-2023.iml +++ b/.idea/djfz-2023.iml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 1ccab34..e557d17 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/TaskG04/run.py b/TaskG04/run.py new file mode 100644 index 0000000..9ee7dad --- /dev/null +++ b/TaskG04/run.py @@ -0,0 +1,25 @@ +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')) \ No newline at end of file