将此文本用阿拉伯语解码

时间:2018-10-18 07:35:17

标签: python decode

我从某个设备接收到的字节中提取以下字符串。 我想将此文本转换为阿拉伯语/乌尔都语

06270631062F0648 。 。 0627 0631 062F 0648

输出应为اردو

这是我的代码:

 1. How is it possible? Could it be because the activity is singleton?
 2. the activity-as-singleton - could it lead to certain problems(like **memory leak** ?, etc..)
 3. Can I count on getActivity always? I think sometimes that too returned null.

我正在获取输出:hexstring = '06270631062F0648' print(binascii.unhexlify(hexstring).decode('utf-16-le'))

here is output image

1 个答案:

答案 0 :(得分:0)

0627、0631、0627和0648是字符串的各个字符的代码点。所以你应该使用:

  • binascii.unhexlify将十六进制字符串转换为字节字符串
  • decode('utf-16-be')将字节字符串解码为utf16 big endian

所以这段代码:

hexstring = "06270631062F0648"
print(binascii.unhexlify(h).decode('utf-16-be'))

给予:

اردو