ord(‘?‘) # 300 ‘?‘.encode(‘utf-16‘) # b‘\xff\xfe,\x01‘ hex(ord(‘,‘)) # 0x2c # 所以得到的是 b‘\xff\xfe\x2c\x01‘ ‘?‘.encode(‘utf-16le‘) # b‘\x2c\x01‘ ‘?‘.encode(‘utf-16be‘) # b‘\x01\x2c‘
s = ‘??‘ s.encode(‘unicode_escape‘) # 这个字符对应的unicode码 # b‘\\U0002a6a5‘ # 把这个看成16进制,对应的十进制为 173733 s.encode(‘utf-16le‘) # b‘i\xd8\xa5\xde‘ # b‘\x69\xd8\xa5\xde‘ s.encode(‘utf-16be‘) # b‘\xd8i\xde\xa5‘ # b‘\xd8\x69\xde\xa5‘ # 充分说明了两点 # 第一,utf-16 大小端,仅在2个字节内倒序 # 第二,utf-16存储4个字节时,和unicode码对应的十六进制不同 hex(ord(‘i‘)) # ‘0x69‘ s.encode(‘utf-32le‘) # b‘\xa5\xa6\x02\x00‘ s.encode(‘utf-32be‘) # b‘\x00\x02\xa6\xa5‘ # 说明 utf-32,存储4个字节时,和unicode码对应的十六进制大致相同 # utf-32,大小端,在4个字节内倒序
http://www.unicode.org/cgi-bin/GetUnihanData.pl?codepoint=2A6A5
Glyphs
The Unicode Standard (Version 3.2) | Your Browser |
---|---|
?? |
Encoding Forms
Decimal | UTF-8 | UTF-16 | UTF-32 |
---|---|---|---|
173733 | F0 AA 9A A5 | D869 DEA5 | 0002A6A5 |
原文:https://www.cnblogs.com/zhouww/p/13544270.html