Hello Friends
For those who managed to calculate CRC 1 and 2, please tell me where is the problem? ..
I translated the code from H2Deetoo:
unsigned long crc_buffer(unsigned long crc, const unsigned long *p, unsigned long sz)
{
const unsigned long poly = 0xEDB88320;
unsigned long tmp1, tmp2;
while(sz--)
{
tmp1 = 0;
tmp2 = crc & poly;
for(int i = 0; i <=31; i++ )
tmp1 ^= ((tmp2 >> i) & 1);
crc = *p++ ^ ((crc << 1) | tmp1) ;
}
return crc;
}
To pascal here is my code:
function CRC32T(Initial: LongWord; Data:array of byte; DataSize: LongWord): LongWord;
const poly=$EDB88320;
var j:integer;
tmp1,tmp2,crc,i:longword;
BEGIN
crc:=initial;
i:=0;
while i<=DataSize-1 do begin
tmp1:=0;
tmp2:=crc and poly;
for j:=0 to 31 do tmp1:=tmp1 xor ((tmp2 shr j) and 1);
crc:=Data[i] xor ((crc shl 1) or tmp1);
i:=i+1;
end;
CRC32T:=crc;
END;
my function seems to work perfectly .. I have checked it with the results of the site crccalc.com
the result is 100/100 identical, of course when I choose 0xFFFFFFFF as initial value, and the result is xored with 0xFFFFFFFF.
This allows me to be sure that there is no error in the implementation of the code.
Now the problem is in the choice of the initial value and the data area.
here is an example:
0x4000 01 00 30 30 00 00 00 00 00 00 00 00 00 00 00 00
0x4010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x4020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x4030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x4040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x4050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x4060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x4070 00 00 00 00 00 00 00 00 2B 00 00 00 C9 B0 BF B2
CRC1 = 3030
CRC2= C9 B0 BF B2
CRC1 Calculation :(From the H2Deetoo document)
Initial value: 00 00 00 01 ; data area from 0x4004 to 0x407F (It seemed strange to me that the crc2 will be included in the data area);
the function return :A1 45 D9 88 which is not correct..
I even wrote an algorithm to permute all the possible cases of the data area..!!
same thing for the choice of the initial value, I made all the permutations you can imagine
Same thing for CRC2
A charitable soul could tell me where I messed up.??