16bit CRC算法C语言实现

#define CRC_16_POLYNOMIALS            0x8005

unsigned short CRC16_3(unsigned char* pchMsg, unsigned short wDataLen) // 1. MSB first; 2. Initial value is 0000;
{
unsigned char i, chChar;
unsigned short wCRC = ;
while (wDataLen--)
{
chChar = *pchMsg++;
wCRC ^= (((unsigned short) chChar) << );
for (i = ; i < ; i++)
{
if (wCRC & 0x8000)
wCRC = (wCRC << ) ^ CRC_16_POLYNOMIALS;
else
wCRC <<= ;
}
} return wCRC;
}

备注:多项式0x8005的含义是: x^15 + x^2 + 1

上一篇:ajax-异步加载片段


下一篇:HTTPD之二————HTTPD服务详解————httpd的配置文件常见设置