CRC32
java官方提供库CRC32 类
byte[] b = new byte[100];
CRC32 c = new CRC32();
c.reset();
c.update(b, 0, b.length);
int value = (int) c.getValue();
自行实现
public static int crc32(byte[] data, int offset,int length){
byte i;
int crc = 0xffffffff;
length += offset;
for(int j=offset;j<length;j++) {
crc ^= data[j];
for (i = 0; i < 8; ++i)
{
if ((crc & 1) != 0)
crc = (crc >> 1) ^ 0xEDB88320;
else
crc = (crc >> 1);
}
}
return ~crc;
}
CRC32/MPEG-2
这个java库没发现 只有自行实现的
public static int crc32_mpeg_2(byte[] data,int offset, int length){
byte i;
int crc = 0xffffffff;
length += offset;
for(int j=offset;j<length;j++) {
crc ^= data[j] << 24;
for (i = 0; i < 8; ++i)
{
if ( (crc & 0x80000000) != 0)
crc = (crc << 1) ^ 0x04C11DB7;
else
crc <<= 1;
}
}
return crc;
}