如何计算 CRC 中使用的 XOR 余数?
我试图记住如何计算循环冗余检查中的 XOR 算法的剩余部分以验证网络消息的剩余位。
我不应该扔掉那本教科书。
这在代码中很容易完成,但是如何手动计算出来呢?
我知道它看起来像标准除法算法,但我不记得从那里去哪里获得余数。
___________
1010 | 101101000
注意:我确实用谷歌搜索了它,但无法找到他们映射计算余数的步骤的地方。
I'm trying to remember how the math is worked out to compute the remainder of an XOR algorithm in Cyclical Redundancy Checks to verify the remainder bits of a network message.
I shouldn't have tossed that text book.
This is easily done in code, but how is it worked out by hand?
I know it looks something like a standard division algorithm, but I can't remember where to go from there to get the remainder.
___________
1010 | 101101000
Note: I did google it, but wasn't able to find a place where they mapped the steps in figuring the remainder.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
因此 101101000 是完美的,传输/接收没有发生错误
Thus 101101000 is perfect and no error has occurred in transmission/reception
根据我的经验,手动计算时将其转换为多项式会更容易,尤其是当有很多零时。
然后将被除数中的最大项 (
x^8
) 除以第一项< /strong> 除数 (x^3
),结果为x^5
。 您将该数字放在顶部,然后乘它与除数中的每一项。 第一次迭代会产生以下结果:对每一项进行异或,然后产生新的被除数:
x5 + x3
:遵循相同的模式,直到被除数的最大项小于除数的最大项。 计算完成后,将如下所示:
本例中的提醒为 0,这表明传输过程中很可能没有发生错误。
注意:在上面的示例中,我将
x^y
缩短为xy
,以减少答案中的混乱,因为 SO 不支持数学方程格式。注2:从被除数中添加/减去除数的倍数也会给出提醒 0,因为
(P(x) + a*C(x)) / C(x) = P(x)/C( x) + a*C(x)/C(x)
与P(x)/C(x)
给出相同的提醒,因为a*C( 的提醒x)/C(x) 为 0。
In my experience it's easier to convert it to a polynomial when calculating by hand, especially when there're a lot of zeroes.
Then you divide the largest term in the dividend (
x^8
) with the first term in the divisor (x^3
), resulting inx^5
. You put that number on top and then multiply it with each term in the divisor. This yields the following for the first iteration:Doing XOR for each term then yields the new dividend:
x5 + x3
:Follow the same pattern until the dividend's largest term is smaller then the divisor's largest term. After the calculations are complete it will look like this:
The reminder in this case is 0, which would indicate that most likely no errors has occurred during the transmission.
Note: I've shortened
x^y
asxy
in the example above to reduce the clutter in the answer, since SO doesn't support math equation formatting.Note2: Adding/subtracting a multiple of the divisor from the dividend will also give the reminder 0, since
(P(x) + a*C(x)) / C(x) = P(x)/C(x) + a*C(x)/C(x)
gives the same reminder asP(x)/C(x)
since the reminder ofa*C(x)/C(x)
is 0.它是除以二进制 11 的长除法。 Wikipedia 上有一个示例。
It is long division by binary 11. There is an example on Wikipedia.
假设我们要将 101110000 除以 1001。
现在我们将删除 XOR 结果开头的零(即 0010)并从顶部滑动数字。
继续对结果执行 XOR 1001。
答案是0011。
Let's assume that we want to divide 101110000 to 1001.
Now we will remove the zeros at the beginning of our XOR result which is 0010 and slide numbers from the top.
Continue the XOR 1001 with the result.
Answer is 0011.