这是参考链接: http://www.w3.org/TR/PNG/ 有人能帮助我理解吗?
http://en.wikipedia.org/wiki/Computation_of_CRC ?
根据维基百科上的CRC列表,这个多项式(也称为AUTODIN II多项式)是最常用的之一。CRC-32-IEEE 802.3 x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1
应用于(以太网、V.42、MPEG-2、PNG、POSIX cksum、Arj、Lha32、Rar、Zip等等...)
使用^
表示幂次重写:
x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 + x^5 + x^4 + x^2 + x + 1.
因此,您可以阅读cksum的源代码,例如在这里
http://www.opensource.apple.com/source/file_cmds/file_cmds-188/cksum/crc32.c
The 32-bit AutoDIN-II CRC is built upon the following shift-register reference model.
Polynomial: g(x) = 1 + x + x^4 + x^5 + x^7 + x^8 + x^10 + x^11 + x^12 + x^1 + x^22 + x^23 + x^26 + x^32
Input data bit 0 first
Leading-zero checking is performed by the following procedure: 1. The crc register is initialized to 0xffffffff, not zero. 2. When a crc is appended, the 32 bits of the crc are inverted. 3. When checking a good message with an appended crc, the register will return to the fixed value of 0xdebb20e3, rather than zero.
[编辑]: 如何使用zlib中的CRC计算器(从zlib文档中提取的C示例)。
#include <zlib.h>
uLong crc = crc32(0L, Z_NULL, 0);
while (read_buffer(buffer, length) != EOF) {
crc = crc32(crc, buffer, length);
}
if (crc != original_crc) error();
crc
的第一次赋值),然后计算您拥有的数据的值(对 crc
的第二次赋值)。每一个 x 项都指代 0xedb88320 的二进制表示中的 1,该数字为 11101101 10111000 10000011 00100000。最左(最低位)端的数字 1 是常数(x^0)项的系数。从左边开始的下一个数字 1 是 x 项的系数。接下来的数字 1 是 x^2 项的系数。下一个数字 0 是 x^3 项的系数(因为 0*x^3 = 0,所以该项缺失)。依此类推。在最右(最高位)端有一个隐含的 1,它是 x^32 项的系数。