📄 crc32.c
字号:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define false 0
#define true 1
char crc_table_is_init = false;
unsigned int crc_table[256];
typedef struct headdef
{
char name[10];
int id;
int crc;
}HEAD,*LPHEAD;
unsigned int crc32(char *buf, long len)
{
unsigned int crc = 0;
if (!crc_table_is_init) {
unsigned int i, j, h = 1;
crc_table_is_init = true;
crc_table[0] = 0;
for (i = 128; i; i >>= 1) {
h = (h >> 1) ^ ((h & 1) ? (int)0xedb88320 : 0);
for (j = 0; j < 256; j += 2*i)
crc_table[i+j] = crc_table[j] ^ h;
}
}
crc ^= 0xffffffff;
while (len--)
crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
return crc ^ 0xffffffff;
}
void main()
{
int a;
HEAD test;
strcpy(test.name,"betty");
test.id=1;
test.crc=crc32(&test,sizeof(HEAD)-4);
//a= crc32(&test,sizeof(HEAD));
printf("a=%x\n",test.crc);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -