CRC校验实用程序库
a;/* 输入的数据 */
unsigned short *accum;/* 指向CRC累加器的指针 */
unsigned short *crctab;/* 指向内存中CRC表的指针 */
{
static short comb-val;
comb-val=(*accum>>8)^data;
*accum=(*accum<<8)^crctab[comb-val];
}
/* 函数crcrevhware是传统的CRC算法的反序算法,其返回值即CRC值 */
unsigned short crcrevhware(data,genpoly,accum)
unsigned short data;
unsigned short genpoly;
unsigned short accum;
{
static int i;
data<<=1;
for(i=8;i>0;i--)
{
data>>=1;
if((data^accum)&0x0001)
else
accum>>=1;
}
return accum;
}
/* 函数crcrevupdate用以用反序查表法计算CRC值并更新CRC累加器值 */
void crcrevupdate(data,accum,crcrevtab)
unsigned short data;
unsigned short *accum;
本文链接地址:http://www.oyaya.net/fanwen/view/172474.html
unsigned short *accum;/* 指向CRC累加器的指针 */
unsigned short *crctab;/* 指向内存中CRC表的指针 */
{
static short comb-val;
comb-val=(*accum>>8)^data;
*accum=(*accum<<8)^crctab[comb-val];
}
/* 函数crcrevhware是传统的CRC算法的反序算法,其返回值即CRC值 */
unsigned short crcrevhware(data,genpoly,accum)
unsigned short data;
unsigned short genpoly;
unsigned short accum;
{
static int i;
data<<=1;
for(i=8;i>0;i--)
{
data>>=1;
if((data^accum)&0x0001)
accum=(accum>>1)^genpoly;
else
accum>>=1;
}
return accum;
}
/* 函数crcrevupdate用以用反序查表法计算CRC值并更新CRC累加器值 */
void crcrevupdate(data,accum,crcrevtab)
unsigned short data;
unsigned short *accum;
《CRC校验实用程序库(第2页)》