举例复盘下 CRC7 的计算过程:
- 原始数据(14bit):11 0100 1110 1100
- CRC(3bit),对应多项式为: X3 + x1 +1 , 即 1011
Step.1:将原始数据(14bit)左移三位,补零:
11010011101100 000 <--- input right padded by 3 bits
1011 <--- divisor (4 bits) = x³ + x + 1
------------------
01100011101100 000 <--- result
Step.2:原始数据(14bit+3bit)逐次去除多项式(1011),实际上就是做异或运算:
11010011101100 000 <--- input right padded by 3 bits
1011 <--- divisor
01100011101100 000 <--- result (note the first four bits are the XOR with the divisor beneath, the rest of the bits are unchanged)
1011 <--- divisor ...
00111011101100 000
1011
00010111101100 000
1011
00000001101100 000 <--- note that the divisor moves over to align with the next 1 in the dividend (since quotient for that step was zero)
1011 (in other words, it doesn't necessarily move one bit per iteration)
00000000110100 000
1011
00000000011000 000
1011
00000000001110 000
1011
00000000000101 000
101 1
-----------------
00000000000000 100 <--- remainder (3 bits). Division algorithm stops here as dividend is equal to zero.
得到 CRC 值为: 100
将数据流:原始数据(14bit)+CRC(3bit)= 11010011101100 100,打包发给接收端。
Step.3:接收端接收到数据后进行校验,即接收到的数据流除以多项式值,没有错误的情况下,其余数一定为零:
11010011101100 100 <--- input with check value
1011 <--- divisor
01100011101100 100 <--- result
1011 <--- divisor ...
00111011101100 100
......
00000000001110 100
1011
00000000000101 100
101 1
------------------
00000000000000 000 <--- remainder