我正在尝试为 12 位 CRC 和算法做 crc_table,但总是得到错误的结果。
你能帮助我吗?要创建 crc 表,我尝试:
void crcInit(void)
{
unsigned short remainder;
int dividend;
unsigned char bit;
for (dividend = 0; dividend < 256; ++dividend)
{
remainder = dividend << 4;
for (bit = 8; bit > 0; --bit)
{
if (remainder & 0x800)
{
remainder = (remainder << 1) ^ 0x180D; //Polynomio of CRC-12
}
else
{
remainder = (remainder << 1);
}
}
crcTable[dividend] = remainder;
}
}
我更新了,CRC算法是:
unsigned short crcFast(unsigned char const message[], int nBytes)
{
unsigned short remainder = 0x0000;
unsigned char data;
int byte;
/*
* Divide the message by the polynomial, a byte at a time.
*/
for (byte = 0; byte < nBytes; ++byte)
{
data = message[byte] ^ (remainder >> 4);
remainder = crcTable[data] ^ (remainder << 8);
}
/*
* The final remainder is the CRC.
*/
return (remainder ^ 0);
}
但它不起作用......