Skip to content

Instantly share code, notes, and snippets.

@mthri
Last active January 2, 2023 08:54
Show Gist options
  • Save mthri/33ca9cf890dc693748b6f04a79d10294 to your computer and use it in GitHub Desktop.
Save mthri/33ca9cf890dc693748b6f04a79d10294 to your computer and use it in GitHub Desktop.
python3 UCS-2 decoder encoder | good for quectel gsm module
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