用Java计算CRC32b [英] Calculate CRC32b in Java

查看:192
本文介绍了用Java计算CRC32b的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用java.util.zip.CRC32,我理解它实现CRC32(而不是CRC32b),但似乎我需要使用CRC32b而不是CRC32。

I use java.util.zip.CRC32 which I understand implements CRC32 (and not CRC32b), but it seems like I need to use CRC32b instead of CRC32.

我有可用于CRC32b计算的Java开源代码吗?

is there a Java open source code I can use for CRC32b calculation?

推荐答案

如果我没记错的话,CRC32b是一个创造性的术语,等于CRC32,反转4个字节。

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);
}

例如输入'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);

输出:

83dcefb7
b7efdc83

给出你的例子结论:java CRC32(没有逆转)没问题。

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

这篇关于用Java计算CRC32b的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆