目前大多数网友分享都是其它多项式公式的CRC8效验码计算
记录一下CRC8效验码的计算, 具体代码如下:
多项式公式 : x8+x2+x+1
public static byte CRC8(byte[] buff)
{
byte crc = 0;
for (int i = 0; i < buff.Length; i++) {
byte crc_u = BitConverter.GetBytes((ushort)(crc ^ buff[i]))[0];
for (int j = 0; j < 8; j++) {
byte crc_o = crc_u;
crc_u = BitConverter.GetBytes((ushort)(crc_u << 1))[0];
if ((crc_o & 0x80) != 0x00)
crc_u = BitConverter.GetBytes((ushort)(0x07 ^ crc_u))[0];
}
crc = crc_u;
}
return crc;
}