uint32 CRC(uint8 *data,uint32 len,uint8 width,uint32 poly,uint32 Init,bool RefIn,bool RefOut,uint32 XorOut) { uint32 i,j,crc,topBit; uint32 dat,wideMask; uint8 bit; topBit=1ul<<(width-1); wideMask=topBit|(topBit-1); crc=wideMask&Init; poly&=wideMask; XorOut&=wideMask; for(i=0;i<len;i ){ dat=*data ; if(RefIn)dat=(uint8)reflect(dat,8); for(j=0;j<8;j ){ bit=0; if(crc&topBit)bit=1; if(dat&0x80)bit^=1; dat<<=1; crc<<=1; if(bit)crc^=poly; } } crc&=wideMask; if(RefOut)crc=reflect(crc,width); return crc^XorOut; }
CRC效验和计算软件 下载地址
参考网址:http://www.skychip.net/post/2012/06/26/1.aspx