gpt4 book ai didi

encoding - 什么字符编码的 e 重音符号为 0xCCA9?

转载 作者:行者123 更新时间:2023-12-01 11:48:02 27 4
gpt4 key购买 nike

我正在尝试读取一个文件,但我无法弄清楚字符编码。文件中有两个字符我知道其值,我在十六进制编辑器中看到的十六进制值如下:

0xCCA9  é
0xCCBB ê
0xCCC1 á

知道这是什么编码吗?

文件中的所有英文字符均采用 ASCII 编码。我有类似的文件,如果有任何用处,这些文件是在 mac central europe 中编码的,也许它们被意外编码了不止一次。

编辑:

在 Python 2.7 中查找映射的代码:(参见上面 Esailija 的回答)。

find_mappings(...) 是一个生成器,它被赋予一个字符映射字典。它遍历所有可用的字符集并生成符合条件的字符集。

import pkgutil
import encodings

def get_encodings():
false_positives = set(["aliases"])
found = set(name for imp, name, ispkg in pkgutil.iter_modules(encodings.__path__) if not ispkg)
found.difference_update(false_positives)
return found

def find_mappings(maps):
encodings = sorted(get_encodings())
for f in encodings:
for g in encodings:
try:
if all([k.decode(f).encode(g) == v for k,v in maps.items()]):
yield (f,g)
except:
# Couldn't encode/decode
pass

for mapping in find_mappings({'\xCC': '\xC3', '\xBB': '\xAA', '\xA9': '\xA9', '\xC1': '\xA1'}):
print(mapping)

最佳答案

它不是任何编码,而是困惑的编码转换的结果。在 UTF-8 中会怎样:

0xC3A9  é
0xC3AA ê
0xC3A1 á

所以我认为最初发生的是 UTF-8 数据在 ASCII 兼容代码页 X 中处理,然后结果被编码到 Mac Central Europe 中的文件。

要获取原始数据,您需要在 Mac Central Europe 中解释文件,在代码页 X 中重新编码结果,并在 UTF-8 中解释重新编码的结果。

我不知道代码页 X 是什么,但它必须具有以下属性,前提是上述内容是正确的:

  • ©编码为0xA9;与 Mac、Windows 和 ISO 编码相同
  • Ő编码为0xC3;排除任何 DOS 代码页
  • Ľ 编码为 0xAA
  • Ń编码为0xA1
  • 是否兼容 ASCII;排除任何 EBCDIC 代码页

关于encoding - 什么字符编码的 e 重音符号为 0xCCA9?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14128729/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com