Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions encoding_decoding.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

# Method encode() returns an encoded version of the string
initial_string = 'Hello there!'
encoded_string = initial_string.encode('utf-32')

# To choose the right Codec for needed language go to the page:
# docs.python.org/3.7/library/codecs.html
# Or choose 'ut-32' as standard for all languages

print('Encoded string of "', initial_string, '" is: ')
print(encoded_string)

# To decode string we need to use decode function
decoded_string = b'\xff\xfe\x00\x00H\x00\x00\x00e\x00\x00\x00l\x00\x00\x00l\x00\x00\x00o\x00\x00\x00 \x00\x00\x00t\x00\x00\x00h\x00\x00\x00e\x00\x00\x00r\x00\x00\x00e\x00\x00\x00!\x00\x00\x00'.decode('utf-32')
print(decoded_string)

# It is possile to use "Fill paragraph" option to show long string in the screen
decoded_string = b'\xff\xfe\x00\x00H\x00\x00\x00e\x00\x00\x00l\x00\x00\x00l\x00\x00\x00o\x00\x00\x00 ' \
b'\x00\x00\x00t\x00\x00\x00h\x00\x00\x00e\x00\x00\x00r\x00\x00\x00e\x00\x00\x00!\x00\x00\x00' \
b''.decode('utf-32')
print(decoded_string)