舉例覆盤下 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