我試圖做crc_table 12位CRC校驗和算法,但總是我得到錯誤的結果。算法CRC-12
你能幫我嗎?要創建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);
}
,但它不工作.....
是這來自UIUC CS438 MP1?我在同一班。 :) – Mysticial
請記住,有三種算法自稱爲CRC-12。所以要確保你正在爲你的目的實施正確的。其他常見多項式是:0x180B和0x180F。同時檢查初始值和最終異或值。 –