python求crc32值的方法

时间:2014-10-08 07:52:24   收藏:0   阅读:226

python求crc32值的方法

python代码中求CRC值,要import binascii
binascii.crc32(v) 求出了v的crc32值,这是一个long型,形如-1456387L,把这个值&0xffffffff得到的值形如48a213L的形式。
然后,把这个值用16进制表示出来。www.jbxue.com
例子:

def _crc32(self, v): 
""" 
Generates the crc32 hash of the v. 
@return: str, the str value for the crc32 of the v 
"""
return 0x%x % (binascii.crc32(v) & 0xffffffff) #取crc32的八位数据 %x返回16进制
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!