I'm using java.util.zip.CRC32 for calculate CRC32. I was detecting weird feature; my app connecting with devices where CRC32 calculated by char array, see simple test:
val i: Int = 123456789
val crc32 = CRC32Any()
crc32.reset()
crc32.update(i)
Timber.i ("CRC32 by int '$i': ${crc32.value}")
crc32.reset()
var arr = ByteBuffer.allocate(Int.SIZE_BYTES)
.putInt(i)
.array()
crc32.update(arr)
Timber.i ("CRC32 by array '${arr.toHexString()}': ${crc32.value}")
crc32.reset()
arr.reverse()
crc32.update(arr)
Timber.i ("CRC32 by reverse arr '${arr.toHexString()}': ${crc32.value}")
And as result:
CRC32 by int '123456789': 3219065702
CRC32 by array '075BCD15': 3488836380
CRC32 by reverse arr '15CD5B07': 417295518
All CRC32 don't match! How to calculate right CRC32 with java.util.zip.CRC32 for correct use?
Solution: