Calculate CRC32b in Java

て烟熏妆下的殇ゞ 提交于 2019-12-01 13:31:44

CRC32b is a coined term if I remember correctly, equal to CRC32 with the 4 bytes reversed.

int crc32b(int crc) {
    ByteBuffer buf = ByteBuffer.allocate(4);
    buf.putInt(crc); // BIG_ENDIAN by default.
    buf.order(ByteOrder.LITTLE_ENDIAN);
    return buf.getInt(0);
}

For instance for input '1':

byte b = (byte) '1';
CRC32 crc = new CRC32();
crc.update(b);

System.out.printf("%x%n", crc.getValue());
int finalCRC = crc32b((int)crc.getValue());
System.out.printf("%x%n", finalCRC);

Output:

83dcefb7
b7efdc83

Given your example the conclusion: java CRC32 (without reversal) is fine.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!