Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Convert CRC

light...light... Member Posts: 1
Please Can anyone convert this code from php to java?

<?php<br />
function bitbybit_crc32($str,$first_call=false){

//reflection in 32 bits of crc32 polynomial 0x04C11DB7

//=0xFFFFFFFF; //keep track of register value after each call
static $reg=0xFFFFFFFF;

//initialize register on first call
if($first_call) $reg=0xFFFFFFFF;

$zeros=$n<4 ? $n : 4;<br />
//xor first $zeros=min(4,strlen($str)) bytes into the register
for($i=0;$i<$zeros;$i++)<br /> $reg^=ord($str{$i})<<$i*8;<br />
//now for the rest of the string
for($i=4;$i<$n;$i++){<br /> $next_char=ord($str{$i});
for($j=0;$j<8;$j++)<br /> $reg=(($reg>>1&0x7FFFFFFF)|($next_char>>$j&1)<<0x1F)<br /> ^($reg&1)*$poly_reflected;

//put in enough zeros at the end
for($i=0;$i<$zeros*8;$i++)<br /> $reg=($reg>>1&0x7FFFFFFF)^($reg&1)*$poly_reflected;

//xor the register with 0xFFFFFFFF
return ~$reg;

$str="123456789"; //whatever
$blocksize=4; //whatever


Sign In or Register to comment.