今天看了一个简单的crc校验代码,挺简单的:
static uint32_t crc32_tab[256];
void make_crc_table(void)
{
uint32_t c;
int n, k;
uint32_t poly; /* polynomial exclusive-or pattern */
//长整形数 c, poly;
/* terms of polynomial defining this crc (except x^32): */
static const uint8_t p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
/* make exclusive-or pattern from polynomial (0xedb88320L) */
poly = 0L; //通过p[], 计算出poly值
for (n = 0; n < sizeof(p); n++)
poly |= 1L << (31 - p[n]);
for (n = 0; n < 256; n++) //再通过poly 算出 crc32_tab[],一共256个值。
{
c = (uint32_t)n;
for (k = 0; k < 8; k++)
c = c & 1 ? poly ^ (c >> 1) : c >> 1;
crc32_tab[n] = c;
}
}
polynomial 是多

本文深入探讨了CRC校验的基本原理,并详细解析了如何生成CRC校验表,帮助读者掌握这一重要的错误检测技术。通过实例代码,阐述了CRC计算过程,使你能够轻松理解和实现CRC校验。
最低0.47元/天 解锁文章
2770

被折叠的 条评论
为什么被折叠?



