CRC16校验程序

CRC循环冗余校验原理参考:http://blog.csdn.net/liyuanbhu/article/details/7882789

const uint16 wCRCTalbeAbs[] = { 0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401, 0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801,0x4400};

uint16 CRC16_2(uint8* pchMsg, uint16 wDataLen)
{
        uint16 wCRC = 0xFFFF;
        uint16 i;
        uint8 chChar;
        for (i = 0; i < wDataLen; i++)
        {
                chChar = *pchMsg++;
                wCRC = wCRCTalbeAbs[(chChar ^ wCRC) & 15] ^ (wCRC >> 4);
                wCRC = wCRCTalbeAbs[((chChar >> 4) ^ wCRC) & 15] ^ (wCRC >> 4);
        }
        return wCRC;
}

你可能感兴趣的:(C/C++)