Practical Session 10 Computer Architecture and Assembly Language
Error detection and correction channel noise data transmission via communication channels channel noise errors may happen reliable delivery of digital data over unreliable communication channels we need techniques that enable reliable delivery of digital data over unreliable communication channels redundancyextra data general idea: add some redundancy (extra data) to a message this extra data is used – to check consistency of the delivered message – to recover data determined to be corrupted – to recover data determined to be corrupted
Hamming Distance Hamming distance (d) amount of 1-bit changes Hamming distance (d) between two code words of equal length is an amount of 1-bit changes required to reach from one word to the other (number of 1’s in the XOR between the words) Minimum Hamming distance smallest Hamming distance all possible pairs Minimum Hamming distance is the smallest Hamming distance between all possible pairs in a set of words. Example: Given the following coding scheme, let’s find the minimum Hamming distance d(00000,01011)=3 d(00000,10101)=3 d(00000,11110)=4 d(01011,10101)=4 d(01011,11110)=3 d(10101,11110)=3 d=3 d(000, 011) = 2 d(10101, 11110) =
Example: errors can take us from one legal code word to another Minimum Hamming Distance d can detect d-1 errors d=3 can detect at least 3-1=2 errors Minimum Hamming Distance d can fix d-1 erasures _0000_0_0 3 erasures can take us from one legal code word to another 0_0__ can detect at least 3-1=2 erasures 2 errors can take us from two different legal code words to the same illegal word Minimum Hamming Distance d can fix errors can fix at least floor((3-1)/2)=1 error
Given four data words, can we use 5-bit code words for fixing 1 error? Answer: yes. We need a hamming distance d=3 to fix 1 error. d(00000,11100)=3 d(11100, 10111)=3 d(00000,10111)=4 d(11100, 01011)=4 d(00000,01011)=3 d(10111, 01011)=3 independent graphs of a single error code words We can create code words with independent graphs of a single error code words
Parity Check parity bit Given a data word, a code word is created by adding a parity bit to the end of the data word d=2 d=2 (why?) Can detect 1 error and fix 1 Can detect 1 error and fix 1 erasure send: receive: 1 error occurs Code word Data word _11 erased bit is a parity of other bits: parity (0011) = 1
Hamming Code (4,3) We calculate: 4 data bits: x0 x1 x2 x33 parity bits: p0 p1 p2 We assume that there may be at most one error. Example: We got p0 = 1 = x3 ⊕ x1 ⊕ x0 = 0 ⊕ 0 ⊕ 1 = 1 √ p1 = 1 = x3 ⊕ x2 ⊕ x0 = 0 ⊕ 1 ⊕ 1 = 0 x p2 = 0 = x3 ⊕ x2 ⊕ x1 = 0 ⊕ 1 ⊕ 0 = 1 x The error bit is at index 6 (from right to left) in the code word error bit is x2 p2 p1 p0 =xx√ = 110 b = 6 12 code word: indexes: why we interleave bits of data and parity in this way ? if p0 is wrong, we get p2 p1 p0 =√√x = 001 b = 1 p0 should be at index 1 if p1 is wrong, we get p1 p1 p0 =√x√ = 010 b = 2 p1 should be at index 2 if p2 is wrong, we get p2 p1 p0 =x√√ = 100 b = 4 p2 should be at index 4 if x0 is wrong, we get p2 p1 p0 =√xx = 011 b = 3 x0 should be at index 3 … if x3 is wrong, we get p2 p1 p0 =xxx = 111 b = 7 x3 should be at index 7 Sender sent
Cyclic Redundancy Check CRC is an error-detecting code Given a data, its non trivial (cryptographic) challenge to find another data with the same CRC code. CRC can protect data (even from deliberate damage)
Binary Pattern as Polynomial
CRC Polynomials (common) CRC-8-ATM x 8 + x 2 + x + 1 CRC-16-IBM x 16 + x 15 + x CRC-16-CCITT x 16 + x 12 + x CRC-32-IEEE 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
Sending – Calculation Steps 1.Generator 1.Generator is chosen – sequence of bits, of which the first and last are 1 2.CRC check sequence is computed 2.CRC check sequence is computed by long- division of message by generator – check sequence has 1 fewer bits than generator appended 3.Check sequence is appended to the original message
Sending – Calculation Steps Compute 8-bit CRC a message ‘W’ (0x57). 1.Select Generator: CRC-8-ATM 1.x 8 + x 2 + x + 1 = ‘W’ is = x 6 + x 4 + x 2 + x Extend ‘W’ with 8 bits: Perform XOR of the word get in step (3) by generator – CRC code is the remainder 5.Append CRC code to ‘W’
Generating CRC Code Generating CRC Code long-division of message by generator CRC Code: xor Each time apply XOR on the extended message, when place a generator from the left-most ‘1’ bit of the extended message Stop when CRC code has 1 fewer bits than generator
Receiving – Calculation Steps Append CRC code to the message: Perform long division by the generator reminder is not 0 If the reminder is not 0: an error occurred result: xor There is no errors in received message.