www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - calculating CRC32

reply chrisalex <chrisalex yahoo.com> writes:
I'm trying to calculate CRC32 and it keeps giving me the wrong 
result.

void main(string[] args)
{
    CRC32Digest test = new CRC32Digest();
    ubyte[] data = [1,5,2,3,4];
    test.put(data);
    auto data2 = test.finish();
    writeln((data2[0] << 24) | (data2[1] << 16) | ((data2[2]) << 
 8) | (data2[3]));
    writeln((data2[0]) | (data2[1] << 8) | ((data2[2]) << 16) | 
 (data2[3] << 24));
}
this writes out
728586467
-480744149
but when calculating CRC32 with java, I get
3814223147
Not sure what I'm doing wrong. I tried reversing data[] as well.
Apr 08 2016
parent zabruk70 <sorry noem.ail> writes:
print result as hex
try to xor result with 0xFFFFFFFF
Apr 08 2016