Python

来源:互联网 发布:Java 优化网站 编辑:程序博客网 时间:2024/05/16 14:04

要点

import binasciihex_digits = binascii.b2a_hex(bin_stream)

生成一个二进制文件

$ dd if=/dev/random of=test.dat bs=5 count=2记录了2+0 的读入记录了2+0 的写出10 bytes copied, 9.6496e-05 s, 104 kB/s$ hexdump -C test.dat00000000  48 ad 45 ec 34 14 48 20  1d e2                    |H.E.4.H ..|0000000a

binascii

>>> import binascii>>> f=open("test.dat", "rb")>>> bin = f.read()>>> f.close()>>> bin'H\xadE\xec4\x14H \x1d\xe2'>>> hex = binascii.b2a_hex(bin)>>> hex'48ad45ec341448201de2'>>> 
原创粉丝点击