我将这些数据存储在一个文件中:
00 00 1a 00 2f 48 00 00 88 9f 5d 04 00 00 00 00
10 04 a8 09 a0 00 c8 00 00 00 80 00 00 00 ff ff
ff ff ff ff 00 25 9c 8f d5 bf 00 25 9c 8f d5 bf
40 7f 04 30 bc 61 02 00 00 00 64 00 21 04 00 05
54 49 52 41 44 01 04 82 84 8b 96 03 01 0d 05 04
00 01 00 00 20 01 00 2a 01 00 32 08 0c 12 18 24
30 48 60 6c dd 18 00 50 f2 02 01 01 03 00 03 a4
00 00 27 a4 00 00 42 43 5e 00 62 32 2f 00 dd 05
00 50 f2 05 00 dd 0e 00 50 f2 04 10 4a 00 01 10
10 44 00 01 02 dd 05 00 09 86 01 00 fe 66 cf c2
我希望使用python来定义一个包含16列和10行的矩阵,其中包含文件中的数据。
请注意,例如ff
或40
代表1个字节。
答案 0 :(得分:0)
data = ''
with open ("in.txt", "r") as in_file:
data = in_file.read().split(' ')
with open ("out.txt", "w") as out_file:
position = 0
for i in data:
if 0 == (position % 16):
out_file.write ("\r\n") #next line windows style. for unix it should be \n
out_file.write ("%s " % i)
position += 1