crc32

The crc32() function in PHP generates the cyclic redundancy checksum (CRC) polynomial of 32-bit lengths of a string, and returns it as an integer.

PHP

$checksum = crc32('hello world');
echo $checksum;
// => 222957957

Ruby

require 'zlib';
puts Zlib.crc32('hello world');
# => 222957957
By | 2009-09-25T13:52:34+00:00 September 17th, 2009|Categories: PHP, Ruby|Tags: , |1 Comment

About the Author:

One Comment

  1. Cristian Livadaru February 13, 2010 at 8:23 pm

    Take care when comparing ruby results with php results. The php manual says:

    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.

    So in case you have a negative number in PHP don’t be afraid, it’s not wrong! Display it with printf(“%u”,$checksum) and compare THAT result o the Ruby result !

Comments are closed.

This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.

This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.