CRC16 计算不太正确

发布于 2024-10-13 19:03:49 字数 1537 浏览 1 评论 0原文

我正在 http://www.ross.net/crc/download/crc_v3.txt 工作,并使用 16 位多项式 0x8005

我的消息是0xAE

本网站 http://www.lammertbies.nl/comm/info/crc-calculation .html 根据我拥有的其他数据生成正确的计算结果。

这是我的代码的输出,描述了每个步骤。

Poly: 1010000000000001
Initial message: 01110101
Message: 011101010000000000000000 24
crcreg: 0000000000000000
crcreg: 0000000000000001
crcreg: 0000000000000011
crcreg: 0000000000000111
crcreg: 0000000000001110
crcreg: 0000000000011101
crcreg: 0000000000111010
crcreg: 0000000001110101
crcreg: 0000000011101010
crcreg: 0000000111010100
crcreg: 0000001110101000
crcreg: 0000011101010000
crcreg: 0000111010100000
crcreg: 0001110101000000
crcreg: 0011101010000000
crcreg: 0111010100000000
crcreg: 1110101000000000
crcreg: 1101010000000000  //Here we had a 1 pop off the shift reg, so we XOR in the poly.
^poly:  1010000000000001
=crcreg:0111010000000001

crcreg: 1110100000000010
crcreg: 1101000000000100
^poly:  1010000000000001
=crcreg:0111000000000101

crcreg: 1110000000001010
crcreg: 1100000000010100
^poly:  1010000000000001
=crcreg:0110000000010101

crcreg: 1100000000101010
crcreg: 1000000001010100
^poly:  1010000000000001
=crcreg:0010000001010101

CRC:    0010000001010101

4 aa
R-CRC:  1010101000000100   //Reversed, just in case MSB/LSB display got hosed.

55 20

预期的 CRC16 为 0xBC81

I am working from http://www.ross.net/crc/download/crc_v3.txt, and using the 16-bit polynomial 0x8005.

My message is 0xAE.

This site http://www.lammertbies.nl/comm/info/crc-calculation.html generates a correct calculation from other data I have.

This is the output from my code, describing each step.

Poly: 1010000000000001
Initial message: 01110101
Message: 011101010000000000000000 24
crcreg: 0000000000000000
crcreg: 0000000000000001
crcreg: 0000000000000011
crcreg: 0000000000000111
crcreg: 0000000000001110
crcreg: 0000000000011101
crcreg: 0000000000111010
crcreg: 0000000001110101
crcreg: 0000000011101010
crcreg: 0000000111010100
crcreg: 0000001110101000
crcreg: 0000011101010000
crcreg: 0000111010100000
crcreg: 0001110101000000
crcreg: 0011101010000000
crcreg: 0111010100000000
crcreg: 1110101000000000
crcreg: 1101010000000000  //Here we had a 1 pop off the shift reg, so we XOR in the poly.
^poly:  1010000000000001
=crcreg:0111010000000001

crcreg: 1110100000000010
crcreg: 1101000000000100
^poly:  1010000000000001
=crcreg:0111000000000101

crcreg: 1110000000001010
crcreg: 1100000000010100
^poly:  1010000000000001
=crcreg:0110000000010101

crcreg: 1100000000101010
crcreg: 1000000001010100
^poly:  1010000000000001
=crcreg:0010000001010101

CRC:    0010000001010101

4 aa
R-CRC:  1010101000000100   //Reversed, just in case MSB/LSB display got hosed.

55 20

The expected CRC16 is 0xBC81

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阳光下慵懒的猫 2024-10-20 19:03:49

您的多项式是相反的:您需要 x 的较高幂的系数由最左边的位表示。尝试反转多项式的位(将其表示为 1000000000000101),我认为您会得到正确的结果。

您可能还需要反转输入和输出,具体取决于您使用的 CRC 特定实现的定义方式(LSB 优先或 MSB 优先)。

Your polynomial is reversed: You need the coefficients for higher powers of x to be represented by the leftmost bits. Try reversing the bits of your polynomial (representing it as 1000000000000101) and I think you'll get the correct result.

You may also need to reverse your input and output, depending on how the particular implementation of CRC you're using is defined (LSB-first or MSB-first).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文