python二进制比较大小的方法_Python中二进制文件的比较

您可以使用^{}进行此操作,下面是一个示例:from itertools import groupby

# this just sets up some byte strings to use, Python 2.x version is below

# instead of this you would use f1 = open('some_file', 'rb').read()

f1 = bytes(int(b, 16) for b in 'FF FF FF FF 00 00 00 00 FF FF 44 43 42 41 FF FF'.split())

f2 = bytes(int(b, 16) for b in '41 42 43 44 00 00 00 00 44 43 42 41 40 39 38 37'.split())

matches = []

for k, g in groupby(range(min(len(f1), len(f2))), key=lambda i: f1[i] == f2[i]):

if k:

pos = next(g)

length = len(list(g)) + 1

matches.append((pos, length))

或者与上面一样使用列表理解:

^{pr2}$

以下是使用Python 2.x时的示例设置:f1 = ''.join(chr(int(b, 16)) for b in 'FF FF FF FF 00 00 00 00 FF FF 44 43 42 41 FF FF'.split())

f2 = ''.join(chr(int(b, 16)) for b in '41 42 43 44 00 00 00 00 44 43 42 41 40 39 38 37'.split())

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值