Polynomial for CRC32:
x 32 + x 26 + x 23 + x 22 + x 16 + x 12 + x 11 + x 10 + x 8 + x 7 + x 5 + x 4 + x 2 + x + 1
Or in hexadecimal and binary:
0x 01 04 C1 1D B7
1 0000 0100 1100 0001 0001 1101 1011 0111
The largest member (x 32 ) is usually not written explicitly, so it can be represented in hexadecimal just like
0x 04 C1 1D B7
Feel free to count 1 and 0, but you will find that they coincide with the polynomial, where 1 is bit 0 (or first bit) and x is bit 1 (or second bit).
Why is this polynomial? Because there must be a standard defined by a polynomial, and the standard has been set by IEEE 802.3. It is also extremely difficult to find a polynomial that efficiently detects various bit errors.
You can think of CRC-32 as a series of “Binary hyphenation-free arithmetic” or basically “XOR and shift operations”. This is technically called polynomial arithmetic.
To better understand this, think about this multiplication:
(x^3 + x^2 + x^0)(x^3 + x^1 + x^0) = (x^6 + x^4 + x^3 + x^5 + x^3 + x^2 + x^3 + x^1 + x^0) = x^6 + x^5 + x^4 + 3*x^3 + x^2 + x^1 + x^0
If we assume that x is base 2, then we get:
x^7 + x^3 + x^2 + x^1 + x^0
What for? Since 3x ^ 3 is 11x ^ 11 (but we only need 1 or 0 preliminary digits), so we transfer:
=1x^110 + 1x^101 + 1x^100 + 11x^11 + 1x^10 + 1x^1 + x^0 =1x^110 + 1x^101 + 1x^100 + 1x^100 + 1x^11 + 1x^10 + 1x^1 + x^0 =1x^110 + 1x^101 + 1x^101 + 1x^11 + 1x^10 + 1x^1 + x^0 =1x^110 + 1x^110 + 1x^11 + 1x^10 + 1x^1 + x^0 =1x^111 + 1x^11 + 1x^10 + 1x^1 + x^0
But mathematicians have changed the rules so that it’s mod 2. Thus, any binary polynomial mod 2 is just addition without hyphenation or XOR. So, our original equation looks like this:
=( 1x^110 + 1x^101 + 1x^100 + 11x^11 + 1x^10 + 1x^1 + x^0 ) MOD 2 =( 1x^110 + 1x^101 + 1x^100 + 1x^11 + 1x^10 + 1x^1 + x^0 ) = x^6 + x^5 + x^4 + 3*x^3 + x^2 + x^1 + x^0 (or that original number we had)
I know this is a leap of faith, but it is beyond my ability as a linear programmer. If you are an experienced CS student or engineer, I challenge to break it. Everyone will benefit from this analysis.
So, to work through a complete example:
Original message : 1101011011 Polynomial of (W)idth 4 : 10011 Message after appending W zeros : 11010110110000
Now we will split the extended message into Poly using CRC arithmetic. This is the same division as before:
1100001010 = Quotient (nobody cares about the quotient) _______________ 10011 ) 11010110110000 = Augmented message (1101011011 + 0000) =Poly 10011,,.,,.... -----,,.,,.... 10011,.,,.... 10011,.,,.... -----,.,,.... 00001.,,.... 00000.,,.... -----.,,.... 00010,,.... 00000,,.... -----,,.... 00101,.... 00000,.... -----,.... 01011.... 00000.... -----.... 10110... 10011... -----... 01010.. 00000.. -----.. 10100. 10011. -----. 01110 00000 ----- 1110 = Remainder = THE CHECKSUM!!!!
The division gives the quotient that we discard and the remainder, which is the calculated checksum. This ends the calculation. Typically, the checksum is then added to the message and the result is transmitted. In this case, the transfer will be: 11010110111110.
Use only a 32-bit number as a divisor, and use the entire stream as a dividend. Throw away the quotient and leave the rest. Attach the remainder at the end of your message and you will have CRC32.
Average guy review:
QUOTIENT ---------- DIVISOR ) DIVIDEND = REMAINDER
- Take the first 32 bits.
- Shift bits
- If 32 bits are less than DIVISOR, go to step 2.
- XOR 32 bits from DIVISOR. Go to step 2.
(Note that the stream must be divided by 32 bits, or it must be supplemented. For example, the 8-bit ANSI stream must be supplemented. Also, at the end of the stream, separation is stopped.)