现在的位置: 首页 > 综合 > 正文

python 求crc32的值

2014年02月26日 ⁄ 综合 ⁄ 共 350字 ⁄ 字号 评论关闭

求CRC值 

前面要import binascii

binascii.crc32(v)  求出了v的crc32值,这是一个long型,形如-1456387L,把这个值&0xffffffff得到的值形如48a213L的形式。。。

然后把这个值用16进制表示出来

    #----------------------------------------------------------------------
    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进制

抱歉!评论已关闭.