您的位置:首页 > 其它

crc16计算

2015-07-13 20:11 246 查看
unsigned short sp_crc16_with_init(unsigned short crc, const unsigned char *buf, int size)

{

unsigned char i;

while(size--!=0)

{

for(i=0x80; i!=0; i/=2)

{

if((crc&0x8000)!=0)

{

crc*=2;

crc^=0x1021;

} /* 余式CRC乘以2再求CRC */

else

{

crc*=2;

}

if((*buf&i)!=0)

{

crc^=0x1021; /* 再加上本位的CRC */

}

}

buf++;

}

return(crc);

}

unsigned short sp_crc16(const unsigned char *buf, int size)

{

return(sp_crc16_with_init(0x00,buf,size));

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: