Last active
January 2, 2023 08:54
-
-
Save mthri/33ca9cf890dc693748b6f04a79d10294 to your computer and use it in GitHub Desktop.
python3 UCS-2 decoder encoder | good for quectel gsm module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import binascii | |
def ucs2_decode(hex_string: str) -> str: | |
return binascii.unhexlify(hex_string).decode('utf-16-be') | |
def ucs2_encode(text: str) -> str: | |
encoded = text.encode('utf-16-be') | |
hexlify = binascii.hexlify(encoded) | |
return hexlify.decode().upper() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment