📄 crc32.c
字号:
/*
crc32.c
Cyclic Redundancy Check (32-bit) for gsLib
Implements the CRC-32 algorithm described in the gzip specs
*/
#include <compress.h>
static unsigned long crc_table[256];
/*
void init_crc_table():
Calculate a table for CRC computation
*/
void init_crc_table()
{
unsigned long c;
int n, k;
for(n = 0; n < 256; n++) {
c = (unsigned long) n;
for(k = 0; k < 8; k++) {
if(c & 1) c = 0xedb88320L ^ (c >> 1);
else c >>= 1;
}
crc_table[n] = c;
}
}
/*
unsigned long update_crc(unsigned long crc,unsigned char *buf, int len):
Updates a running crc with the bytes buf[0..len-1] and returns the updated
crc
*/
unsigned long update_crc(unsigned long crc,unsigned char *buf, int len)
{
unsigned long c = crc ^ 0xffffffffL;
int n;
for(n = 0; n < len; n++)
c = crc_table[(c ^ buf[n]) & 0xff] ^ (c >> 8);
return c ^ 0xffffffffL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -