Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试读取二进制文件并返回例如“ffffff”一系列 6 个十六进制代码。这有意义吗?我的代码(下面)只返回一个 2 的列表,所以它看起来像“ff”
fp = open(f, 'rb') hex_list = ("{:02x}".format(ord(c)) for c in fp.read())
我特别想让这个回报像
['ab0012', 'ffbaf0']
不喜欢
['ab', '00', '12', 'ff', 'ba', 'f0']
任何帮助将不胜感激。
这个怎么样:
fp = open(f, 'rb') hex_list = ["{:02x}".format(ord(c)) for c in fp.read()] return [''.join(hex_list[n:n+3]) for n in range(0, len(hex_list), 3)]