python求crc32值的方法

yipeiwu_com5年前Python基础

本文实例讲述了python求crc32值的方法。分享给大家供大家参考。具体实现方法如下:

要想求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进制

希望本文所述对大家的Python程序设计有所帮助。

相关文章

python ceiling divide 除法向上取整(或小数向上取整)的实例

向上取整的方法: 方法1: items = 102 boxsize = 10 num_boxes = (items + boxsize - 1) // boxsize 方法2:...

在Python的Tornado框架中实现简单的在线代理的教程

实现代理的方式很多种,流行的web服务器也大都有代理的功能,比如http://www.tornadoweb.cn用的就是nginx的代理功能做的tornadoweb官网的镜像。 最近,我...

浅析python中while循环和for循环

while循环 只要循环条件为True(以下例子为x > y),while循环就会一直 执行下去: u, v, x, y = 0, 0, 100, 30 ⇽...

用smtplib和email封装python发送邮件模块类分享

复制代码 代码如下:#!/usr/bin/python# encoding=utf-8# Filename: send_email.pyfrom email.mime.image imp...

Python中用Descriptor实现类级属性(Property)详解

上篇文章简单介绍了python中描述器(Descriptor)的概念和使用,有心的同学估计已经Get√了该技能。本篇文章通过一个Descriptor的使用场景再次给出一个案例,让不了解情...