显示十六进制文件的内容
#!/usr/bin/python
# -*- coding:utf-8 -*-
#s = "Hello world !!"
#":".join("{:02x}".format(ord(c)) for c in s)
header=bytes(256);
#header=[]
with open('dsp1.elf',"rb") as f:
f.seek(0,0) #SEEK_SET
header=f.read(256)
def showChr(list1):
for i in list1:
if(chr(i).isalnum()):
vv=i
print('{:2c}'.format(vv),end=' ')
else:
vv=0
print('{:2x}'.format(vv),end=' ')
print(end='\n')
#Display in decimal format
for i,v in enumerate(header):
if(i==0):
print('{:>8d}:{:3d}'.format(i,v),end='')
elif (i%16==0):
print('{:>8x}:{:3d}'.format(i,v),end='')
else:
if((i+1)%16==0):
print('{:3d}'.format(v),end='||')
showChr(header[i-15:i])
else:
print('{:3d}'.format(v),end=' ')