PYTHON crc32

is this article helpful?
|
Python replacement for PHP's crc32 [ edit | history ]
import binascii
result = binascii.crc32(myStr) & 0xffffffff



mysql> SELECT crc32('edicarlo');
result: 3004382837
OK

php> print crc32('edicarlo');
result: 3004382837
OK

python> print binascii.crc32('edicarlo')
result: -1290584459
:(

python> print binascii.crc32('edicarlo') & 0xffffffff
result: 3004382837
OK

PHP crc32

PHP original manual for crc32 [ show | php.net ]

crc32

(PHP 4 >= 4.0.1, PHP 5)

crc32Calculates the crc32 polynomial of a string

Description

int crc32 ( string $str )

Generates the cyclic redundancy checksum polynomial of 32-bit lengths of the str . This is usually used to validate the integrity of data being transmitted.

Because PHP's integer type is signed, and many crc32 checksums will result in negative integers, you need to use the "%u" formatter of sprintf() or printf() to get the string representation of the unsigned crc32 checksum.

Parameters

str

The data.

Return Values

Returns the crc32 checksum of str as an integer.

Examples

Example #1 Displaying a crc32 checksum

This example shows how to print a converted checksum with the printf() function:

<?php
$checksum 
crc32("The quick brown fox jumped over the lazy dog.");
printf("%u\n"$checksum);
?>

See Also

  • md5() - Calculate the md5 hash of a string
  • sha1() - Calculate the sha1 hash of a string