from __future__ import print_function

f = open('test.pcm','rb')
n = 0;
s = f.read(1)
while s:
        byte = ord(s)
        n = n+1
        print('0x%02x,'%(byte),end='')
        if n%16==0:
                print('')
        s = f.read(1)
print('\n\ntotal bytes: %d'%n)
f.close()

 

更多推荐

Python 读文件并按十六进制输出