Answer the question
In order to leave comments, you need to log in
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
I will write my own version based on the zedxxx version :
import binascii
print(binascii.hexlify('Привет!!!'.encode('utf-16-be')).decode('utf-8').upper())
>>> import binascii
>>> binascii.hexlify('Привет!!!'.decode('cp866').encode('utf-16-be'))
'041f04400438043204350442002100210021'
>>>
>>> s = 'Привет!!!'
>>> ''.join(format(i, '02X') for i in s.encode('utf-16-be'))
'041F04400438043204350442002100210021'
>>>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question