//CRC位域4表(大端): const unsigned int CRCL16_1021_Table[16] = { 0x0000,0x1021,0x2042,0x3063,0x4084,0x50A5,0x60C6,0x70E7,0x8108,0x9129,0xA14A,0xB16B,0xC18C,0xD1AD,0xE1CE,0xF1EF }; //CRC位域4查表算法(大端): unsigned int GetCRCL16_1021_FFFF_0000_Table(unsigned char *crcBuff, unsigned char crcLen) { unsigned char i; unsigned int crc = 0xFFFF; unsigned char crcTemp; for(i = 0; i < (crcLen * 2); i ++) { if (i & 1) crcTemp = crcBuff[i >> 1] & 0x0F; else crcTemp = crcBuff[i >> 1] >> 4; crc = (crc << 4) ^ CRCL16_1021_Table[(crc >> 12) ^ crcTemp]; } return crc; } void main() { const unsigned char dataTable[] = "\x01\x23\x45\x67\x89\xAB\xCD\xEF"; unsigned int crc; crc = GetCRCL16_1021_FFFF_0000_Table((unsigned char *)dataTable, sizeof(dataTable) - 1); while(1); } |