CRC32 C语言源码

unsigned int Xcrc32(unsigned int crc, const void *base, unsigned int len)
{
	unsigned int crc32 = 0;
	unsigned char *p = (unsigned char *)base;
	const unsigned int table[16] = {
		0x00000000, 0x1DB71064, 0x3B6E20C8, 0x26D930AC, 0x76DC4190, 0x6B6B51F4, 0x4DB26158, 0x5005713C,
		0xEDB88320, 0xF00F9344, 0xD6D6A3E8, 0xCB61B38C, 0x9B64C2B0, 0x86D3D2D4, 0xA00AE278, 0xBDBDF21C
	};

  crc32 = table[(crc ^  *p        ) & 0x0F] ^ (crc >> 4);
	crc32 = table[(crc32 ^ (*p++ >> 4)) & 0x0F] ^ (crc32 >> 4);
  len--;
	while (len--) {
		crc32 = table[(crc32 ^  *p        ) & 0x0F] ^ (crc32 >> 4);
		crc32 = table[(crc32 ^ (*p++ >> 4)) & 0x0F] ^ (crc32 >> 4);
	}
	return crc32;
}
// 注:支持分包和整包计算,计算结果不会变。

You may also like...

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据