unsigned long crc(unsigned char *p,unsigned long len)
{
unsigned long poly = 0x400007;
unsigned long bcrc = 0;
unsigned long tap = 0;
unsigned char crcf = 0;
unsigned long i;
for (i=0;i<len;i++)
{
crcf = (unsigned char)(bcrc>>31);
bcrc <<= 1;
tap = 0;
if(p[i]&0x01)
tap |= 0x01;
if(p[i]&0x02)
tap |= 0x08;
if(p[i]&0x04)
tap |= 0x20;
if(p[i]&0x08)
tap |= 0x100;
if(p[i]&0x10)
tap |= 0x400;
if(p[i]&0x20)
tap |= 0x2000;
if(p[i]&0x40)
tap |= 0x10000;
if(p[i]&0x80)
tap |= 0x40000;
bcrc = tap^bcrc;
if(crcf)
{
bcrc = poly^bcrc;
}
}
return bcrc;
}
int main(int argc, char* argv[])
{
unsigned long c;
c = crc(buffer,sizeof(buffer));
printf("crc result is %x\n",c);
getchar();
return 0;
}