CRC, the full name of "Cyclic Redundancy Check, is cyclic redundancy check. It is a channel coding technology commonly used in detecting or verifying data. In fact, it is a short check code generated from the original data, such as CRC8, CRC8 /MAXIM, CRC16/MAXIM, CRC32, etc. The following introduces some commonly used C language implementation methods for generating CRC check codes.
CRC-8 / MAXIMUM | (Lol) |
---|---|
Parametric model name | x 8+x5+x4+1 |
Width WIDTH | 8 |
Polynomial POLY | 0x31 |
Initial value INIT | 0x00 |
Result or value XOROU | 0x00 |
Input data inversion REFIN | YES |
Output data inversion REFOUT | YES |
PART algorithm implementation
uint8_t crc8_MAXIM(uint8_t *data, uint8_t len)
{
uint8_t crc, i;
crc = 0x00;
while(len--)
{
crc ^ = *data++;
for(i = 0;i < 8;i++)
{
if(crc & 0x01)
{
crc = (crc >> 1) ^ 0x8c;
}
else crc >>= 1;
}
}
return crc;
}
PS: By the way, an algorithm for exchanging the high and low bits of Byte (butterfly exchange method) is attached.
PART algorithm implementation
uint8_t Byte_shift(uint8_t data)
{
data = (data << 4)|(data >> 4);
data = ((data << 2) & 0xcc) | ((data >> 2) & 0x33);
data = ((data << 1) & 0xaa) | ((data >> 1) & 0x55);
return data;
}
the above.