I already have working examples that calculate CRC-8, CRC-16, CRC-32 in Java but they are different implementations and I am a bit confused. I tried to read the math tech docs, but it seems a bit too much for my math level. Also, converting code from C/C++ is not as straight forward since Java does not do well with unsigned primitives...
I need a complete example to understand and be able to verify my checksums since there are a lot of different polynomials out there!
See Best CRC Polynomials by Philip Koopman and CRC Hamming Weight Data by Philip Koopman.
I would appreciate if anyone can provide a minimum but detailed example in Java that for e.g. CRC-8, does:
- Calculates the checksum of a byte array (without lookup table).
- Programmatically create the crc lookup table.
- Calculates the checksum of a byte array using the lookup table.
This is what I managed to put together for CRC-8. Still, I cannot fully understand how the polynomial is produced, especially why we should/could use the reversed version! I also miss a CRC-16, CRC-32 and maybe a CRC-64 complete example as the one I provide below. Hopefully someone else will fulfill this need in the future.
This code uses
polynomial: 0xa6 = x^8 + x^6 + x^3 + x^2 + 1 (0x14d) <=> (0xb2; 0x165)
as Mark Adler suggests here and based on these tests that shows the strength of this polynomial.