CRC: catching burst errors
لم يُترجم بعد؛ يُعرض باللغة الإنجليزية
عن هذا الدرس
Noise on a real channel rarely flips one lone bit: a click of interference flips a run of neighbouring bits, a burst. A cyclic redundancy check (CRC) is built to catch exactly that. Follow one by hand: the message 11010011 is read as a polynomial, divided by the generator G = 1011 (x³ + x + 1) using XOR, and the 3-bit remainder 011 rides along as the check. The receiver divides again; remainder 000 means accept. You will see why every burst of up to 3 bits is caught, which longer bursts slip through, and how Ethernet uses the same idea with CRC-32. This goes deeper than the Networking lesson on Ethernet frames; it builds on the lesson on parity and Hamming codes.
Noise comes in bursts
A spike of interference does not flip one lone bit. It lasts a while, so it flips a run of neighbouring bits: a burst. Here one click flips 3 bits in a row. A single parity bit misses any even number of flips.
line: +1 V = bit 1, −1 V = bit 0
one bit every 1 µs
sent 11010011011
received 11011101011
^^^ bits 4, 5, 6 flipped
burst = errors packed close together
(scratches, lightning, a motor switching on)
parity: 2 flips cancel out, unseenاقرأ الدرس خطوة بخطوة
Noise comes in bursts
A spike of interference does not flip one lone bit. It lasts a while, so it flips a run of neighbouring bits: a burst. Here one click flips 3 bits in a row. A single parity bit misses any even number of flips.
line: +1 V = bit 1, −1 V = bit 0 one bit every 1 µs sent 11010011011 received 11011101011 ^^^ bits 4, 5, 6 flipped burst = errors packed close together (scratches, lightning, a motor switching on) parity: 2 flips cancel out, unseenBits as a polynomial
Read the 8 message bits as coefficients of powers of x: 11010011 is x⁷ + x⁶ + x⁴ + x + 1. Sender and receiver agree on a generator G = 1011, that is x³ + x + 1. It has degree 3.
bit: 1 1 0 1 0 0 1 1 power: x⁷ x⁶ x⁵ x⁴ x³ x² x¹ x⁰ M(x) = x⁷ + x⁶ + x⁴ + x + 1 G(x) = x³ + x + 1 (bits 1011) coefficients are only 0 or 1 and 1 + 1 = 0 (arithmetic mod 2)Make room: append 3 zeros
G has degree 3, so the check will be 3 bits long. The sender appends 3 zeros: 11010011000. That is the message times x³, and the zeros hold the place where the check bits will go.
M(x)·x³ = shift left by 3 11010011 -> 11010011000 11 bits now: 8 message + 3 places for the check bits the bit labels count from the left: bit i is the power x^(10−i), so bit 0 = x¹⁰ and bit 10 = x⁰Divide by G with XOR
Now divide by G the binary way. Wherever the leftmost bit still left is 1, line G up under it and XOR: equal bits give 0, different give 1. No carries, no borrows. Zeros are skipped. 5 XORs clear the message.
11010011000 1011 XOR at bit 0 01100011000 1011 XOR at bit 1 00111011000 1011 XOR at bit 2 00010111000 1011 XOR at bit 3 00000001000 1011 XOR at bit 7 00000000011 bits 4, 5, 6 were already 0: skippedThe remainder is the CRC
What is left in the last 3 places is the remainder, 011: the CRC. The XORs only wiped a working copy; the sender still has the message. The CRC takes the place of the zeros: the frame is 11010011 011.
remainder R(x) = 011 (= x + 1) frame T = M·x³ + R = 11010011 011 in mod 2, adding R is the same as subtracting it, so T = G × (something): T divides by G exactlySend the frame
The sender puts all 11 bits on the cable: 11010011 then 011. In mod 2, adding the remainder is the same as subtracting it, so the frame is an exact multiple of G. Anything else will not be.
on the cable: 11010011011 T(x) = x¹⁰ + x⁹ + x⁷ + x⁴ + x³ + x + 1 = G(x) × Q(x) 3 extra bits for 8 message bits (Ethernet: 32 extra bits for up to 1500 payload bytes)Receiver: remainder 000
The receiver divides all 11 bits by the same G, check bits included. A clean frame is a multiple of G, so the remainder is 000. Accept. The receiver never needs a second copy of the message.
11010011011 1011 01100011011 1011 00111011011 1011 00010111011 1011 00000001011 1011 00000000000 remainder 000 -> acceptA burst hits: remainder ≠ 000
Now the burst flips bits 4, 5 and 6. The receiver gets 11011101011. It divides as before and is left with 100, not 000. Reject: the frame is thrown away and sent again.
sent 11010011011 error E 00001110000 received 11011101011 received ÷ G -> remainder 100 remainder ≠ 000 -> reject, retransmit (the CRC only detects; it does not fix bits like a Hamming code)Why every short burst is caught
Received = frame + error E; the frame divides by G, so only E matters. A burst of up to 3 bits is E = xⁱ·B, B of degree below 3. G has degree 3 and a +1 term, so it cannot divide that. Caught.
received(x) = T(x) + E(x) remainder of received = remainder of E burst here: bits 4, 5, 6 (from the left) = powers x⁶, x⁵, x⁴ E = x⁶ + x⁵ + x⁴ = x⁴·(x² + x + 1) B has degree < 3: G cannot divide B G has the +1 term: G shares no factor with xⁱ -> G never divides E: caught, every time plot: every burst length 1..3: 100 %Some longer bursts slip through
A burst of 4 bits can be G itself, shifted. Here E = 1011 at bit 5: the remainder is 000 and the bad frame is accepted. Trying every burst: 1 in 4 of length 4 slips, 1 in 8 of longer ones.
sent 11010011011 error E 00000101100 received 11010110111 bits 5, 7, 8 (from the left) = powers x⁵, x³, x² E = x⁵ + x³ + x² = x²·G(x): a multiple of G remainder 000 -> accepted, wrongly caught, counted over all bursts: length 1: 11/11 = 100.0 % length 2: 10/10 = 100.0 % length 3: 18/18 = 100.0 % length 4: 24/32 = 75.0 % length 5: 49/56 = 87.5 % length 6: 84/96 = 87.5 % length 7: 140/160 = 87.5 % length 8: 224/256 = 87.5 %The same division in Python
A Python integer holds the bits; Python counts bit i from the right, as the power xⁱ. Shifting left by 3 appends the zeros. Walk from bit 10 (lamp 0) to bit 3; where a bit is 1, XOR in G. Left: 0b11, the CRC.
g = 0b1011 # x^3 + x + 1 a = 0b11010011 << 3 # 3 zeros for i in range(10, 2, -1): if a >> i & 1: a ^= g << i-3 >>> bin(a) '0b11' # the CRC 011 a >> i & 1 reads bit i (from the right: Python bit i = lamp 10−i) g << i-3 lines G up under bit i ^ XOR (Python 3, integers only)CRC-32 in every Ethernet frame
Ethernet does exactly this with a degree-32 generator (0x04C11DB7): 32 check bits per frame. It catches every burst up to 32 bits long. Real CRC-32 also starts from all ones and inverts the result; Python's zlib.crc32 computes it.
CRC-32 (IEEE 802.3 frame check sequence) G = 0x04C11DB7 (+ the x³² term) bursts ≤ 32 bits: always caught 33-bit bursts: about 1 in 2³¹ slip longer bursts: about 1 in 2³² slip >>> import zlib >>> hex(zlib.crc32(b"123456789")) '0xcbf43926' extra details: register starts at 0xFFFFFFFF, bits go in low bit first, the result is inverted
أسئلة سريعة: 5
اختر إجابة واحدة لكل سؤال. يمكنك تغيير اختياراتك قبل التحقق منها.
01What is 1011 XOR 1110?
XOR works bit by bit with no carries: equal bits give 0, different bits give 1. 1⊕1 = 0, 0⊕1 = 1, 1⊕1 = 0, 1⊕0 = 1, so 0101. 11001 is ordinary addition with carries, which CRC arithmetic never uses.
02The generator is G = 1011 (degree 3). How many zeros does the sender append to the message before dividing?
As many as the degree of G, which is also the length of the remainder: 3. The 3 zeros (multiplying the message by x³) hold the places where the 3 check bits go.
03A receiver using G = 1011 divides a received frame and gets remainder 010. What does it do?
A frame that left the sender is an exact multiple of G, so its remainder is 000. Any other remainder means some bits changed on the way. A CRC detects errors; it does not say which bits to fix, so the usual answer is to throw the frame away and retransmit.
04Which errors is a 32-bit CRC such as Ethernet's CRC-32 certain to catch?
An r-bit CRC whose generator has a +1 term catches every single burst of length r or less, so CRC-32 catches every burst of up to 32 bits. Longer bursts are caught almost always, but not always: about 1 in 2³¹ bursts of 33 bits slips through, and about 1 in 2³² of longer ones.
05With G = 1011, a burst flips bits so that the error pattern is exactly 1011, shifted to some position. What happens?
The remainder only depends on the error pattern E. If E is G times a power of x, E divides by G exactly, the remainder is 000, and the damaged frame looks clean. That is why 1 of the 4 possible bursts of length 4 slips past this 3-bit CRC.
المسرد
- Burst error
- A group of bit errors packed close together, from the first flipped bit to the last; its length counts every bit in between. Caused by clicks of interference, scratches, fades.
- Cyclic redundancy check (CRC)
- An error-detecting code: the check bits are the remainder of dividing the message (with zeros appended) by an agreed generator polynomial, using mod-2 arithmetic.
- Generator polynomial G(x)
- The divisor sender and receiver agree on, written as bits (1011 = x³ + x + 1). Its degree r is the number of check bits.
- Mod-2 arithmetic
- Arithmetic on bits where 1 + 1 = 0 and there are no carries or borrows; adding and subtracting are both XOR.
- XOR
- Exclusive or: 1 when two bits differ, 0 when they are equal.
- Remainder (syndrome)
- What is left after the division. At the sender it becomes the check bits; at the receiver, 000 means no error was detected.
- Frame check sequence (FCS)
- The 32-bit CRC at the end of every Ethernet frame (generator 0x04C11DB7).
الملاحظات والمصادر
- Every bit in the figure comes from the model: the message 11010011, the generator 1011 (x³ + x + 1, listed as CRC-3-GSM), the remainder 011 and both bursts are computed, and the bar chart is made by trying every burst of each length at every position in the 11-bit frame.
- The line plot is an example: polar NRZ (+1 V for a 1, −1 V for a 0) at one bit per microsecond, with an interference click modelled as a decaying oscillation. The receiver reads each bit in the middle of its slot.
- Real CRC-32 (Ethernet, zlib) presets the register to all ones, feeds each byte low bit first and inverts the result; the error-catching comes from the same division by G.
- Cyclic redundancy check (Wikipedia): an n-bit CRC detects any single burst of up to n bits; CRC-3-GSM x³ + x + 1; CRC-32 0x04C11DB7 used by IEEE 802.3
- Computation of cyclic redundancy checks (Wikipedia): polynomial division modulo two with XOR, appended zeros, all-ones preset, final inversion
- Burst error-correcting code (Wikipedia): cyclic codes detect all bursts of length up to r = n − k, and most longer ones
- Ethernet frame (Wikipedia): four-octet CRC frame check sequence, polynomial 0x04C11DB7, initial value 0xFFFFFFFF, complemented result
- MIT OpenCourseWare 6.02 (Fall 2012), Bits, Signals, and Packets, ch. 5: bursts on channels and storage media; CRC-32 signature and retransmission
- MIT OpenCourseWare 6.02 Introduction to EECS II: Digital Communication Systems, readings
- L. L. Peterson and B. S. Davie, Computer Networks: A Systems Approach (textbook, free online edition), §2.4.2 Cyclic Redundancy Check: messages as polynomials, appending k zeros, mod-2 division, burst detection
- Python documentation: zlib.crc32 (unsigned 32-bit CRC checksum)
اختبار يتاح بعد الخطوة الأخيرة.