1
\$\begingroup\$

According to the Bluetooth Core 4.0 specification, the Bluetooth Low Energy air packet has a 24-bit CRC with the following polynomial:

x^24 + x^10 + x^9 + x^6 + x^4 + x^3 + x + 1

But, when I "encode" this polynomial, I get 4 bytes:

XXXXXXX1 00000000 00000110 01011011

What am I missing?

\$\endgroup\$
  • \$\begingroup\$ Wouldn't x24 through x0 be 25 bits? \$\endgroup\$ – Ignacio Vazquez-Abrams Nov 13 '13 at 2:42
  • \$\begingroup\$ @IgnacioVazquez-Abrams I also think so, but the specification explicitly says that the CRC has 24 bits and my radio module, which is Bluetooth Low Energy "compliant", has a CRC field with exactly 24 bits. \$\endgroup\$ – borges Nov 13 '13 at 2:47
  • \$\begingroup\$ Do they show any example messages, including the CRC? \$\endgroup\$ – Ignacio Vazquez-Abrams Nov 13 '13 at 2:58
3
\$\begingroup\$

You will always have CRC 1 bit less than width of polynomial. CRC is remainder of long division operation. This long division is performed using polynomial arithmetic where subtraction is simply XORing corresponding bits. You start using first 25 bits of message as dividend polynomial. Condition that says divisor polynomial "goes" into this 25-bit dividend polynomial is only when order of this polynomial is same as CRC polynomial, that is bit 24 is 1. When that happens, you simply XOR these 25-bits with each other. This ensures that bit 24 always goes to zero after each partial division resulting in 24-bit remainder. If bit 24 from dividend polynomial is not 1, you simply skip that bit and go to next one till you find 1. For each bit skipped, a bit is pulled from the message. This repeats all the way to the end of the message. So in the end you always have remainder of 24 bits.

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

It is normal for CRC polynomials to be 1 bit longer than nominal : the leading bit is incoming, not stored. This section of the Wiki article gives more information.

I also found this article useful when implementing a CRC recently despite the documentation pointing me at the wrong polynomial...

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.