如果您有一串位,如果0
s 和1
s 的字符串采用 utf-8 编码,您如何将其转换为正确的代码点。
例如:
accented_a_part1 = "100001"
accented_a_part2 = "00011"
accented_a_int = int(accented_a_part2 + accented_a_part1, 2)
print(accented_a_int), # => 225
print(unichr(accented_a_int)) # => á http://www.unicode.org/charts/PDF/U0080.pdf
accented_a_in_utf8 = "110" + accented_a_part2 + "10" + accented_a_part1
accented_a_in_utf8_as_raw_int = int(accented_a_in_utf8, 2)
print(accented_a_in_utf8_as_raw_int), # => 50081 (not the codepoint you want)
print(unichr(accented_a_in_utf8_as_raw_int)) # => 쎡 (and therefore not the character you want)