void CRC_calcCrc8(u16 *crcReg, u16 poly, u16 u8Data)
{
u16 i;
u16 xorFlag;
u16 bit;
u16 dcdBitMask = 0x80;
for(i=0; i<8; i++)
{
// Get the carry bit. This determines if the polynomial should be
// xor'd with the CRC register.
xorFlag = *crcReg & 0x8000;
// Shift the bits over by one.
*crcReg <<= 1;
// Shift in the next bit in the data byte
bit = ((u8Data & dcdBitMask) == dcdBitMask);
*crcReg |= bit;
// XOR the polynomial
if(xorFlag)
{
*crcReg = *crcReg ^ poly;
}
// Shift over the dcd mask
dcdBitMask >>= 1;
}
}
翻译为C#代码 谢了 有计算crc好多方法也可以呢