J
J
jack_ganakock2015-12-25 14:38:38
Python
jack_ganakock, 2015-12-25 14:38:38

Python 3.4 how to encode a string in UCS2?

The string "Hi!!!"
The output should be: "041F04400438043204350442002100210021"
Please help.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
T
TomasHuk, 2015-12-25
@jack_ganakock

I will write my own version based on the zedxxx version :

import binascii
print(binascii.hexlify('Привет!!!'.encode('utf-16-be')).decode('utf-8').upper())

Z
zed, 2015-12-25
@zedxxx

>>> import binascii
>>> binascii.hexlify('Привет!!!'.decode('cp866').encode('utf-16-be'))
'041f04400438043204350442002100210021'
>>>

A
abcd0x00, 2015-12-25
@abcd0x00

>>> s = 'Привет!!!'
>>> ''.join(format(i, '02X') for i in s.encode('utf-16-be'))
'041F04400438043204350442002100210021'
>>>

V
Vladimir, 2015-12-25
@vintello

You will send SMS :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question