bit by bit crc32 computation
<?php
function bitbybit_crc32($str,$first_call=false){
$poly_reflected=0xEDB88320;
static $reg=0xFFFFFFFF;
if($first_call) $reg=0xFFFFFFFF;
$n=strlen($str);
$zeros=$n<4 ? $n : 4;
for($i=0;$i<$zeros;$i++)
$reg^=ord($str{$i})<<$i*8;
for($i=4;$i<$n;$i++){
$next_char=ord($str{$i});
for($j=0;$j<8;$j++)
$reg=(($reg>>1&0x7FFFFFFF)|($next_char>>$j&1)<<0x1F)
^($reg&1)*$poly_reflected;
}
for($i=0;$i<$zeros*8;$i++)
$reg=($reg>>1&0x7FFFFFFF)^($reg&1)*$poly_reflected;
return ~$reg;
}
$str="123456789"; $blocksize=4; for($i=0;$i<strlen($str);$i+=$blocksize) $crc=bitbybit_crc32(substr($str,$i,$blocksize),!$i);
?>