我有一个包含无符号 64 位整数的文件,格式如下所示
0100 0000 0000 0000
0200 0000 0000 0000
0300 0000 0000 0000
3655 9d80 0f00 0000
7a64 dae3 0900 0000
060f fa3f 0600 0000
我正在寻找一种方法来读取这些数字,然后将它们转换为十进制等值
我目前的代码如下:
filename = "C:\\RainbowTables\\md5_loweralpha-numeric#1-7_0_2x50_0.rt"
blocksize = 8
with open(filename, "rb") as f:
startpoint = f.read(blocksize)
string = ""
for ch in startpoint:
string += hex(ord(ch))
print string
这给了我第一个数字的以下输出
0x10x00x00x00x00x00x00x0
我一直在研究如何为此使用结构,因为看起来它就是为此而设计的,但我一直无法找到使用它们的正确语法。
如有任何帮助,我们将不胜感激!
最佳答案
import struct
decoded = []
with open("some_bin_file.rt","rb") as f:
while True:
try:
decoded.append(struct.unpack_from("<Q",f)[0])
# `<` means little endian; `Q` means unsigned long long (8 bytes)
except struct.error:
break
print decoded
我认为应该可以...
关于python - 从文件中读取小端并转换为十进制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24965862/