160 likes | 283 Views
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization & Assembly Language Lecture 7 (Computer System Organization) Error Detection & Correction. Outline. From Text Book: 2.2.4
E N D
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization & Assembly Language Lecture 7 (Computer System Organization) Error Detection & Correction
Outline • From Text Book: 2.2.4 • Error Detection & Error Correction • Hamming Distance • Hamming Algorithm Error Detection & Error Correction
Error Detection & Correction Error Detection & Error Correction • Computer memories could make errors due to electric spikes leading to incorrect behavior • To protect against such behavior, two ways are adopted • Error-detection codes • Error-Correction codes • Extra bits are added to the memory word in a special way so that when the word is read out from memory these extra bits are checked for errors
m r n (codeword) Memory Errors – Code words Error Detection & Error Correction • Consider a memory word of size m bits to which r redundant check bits are added • The total length of the unit is n = m+ r • This n bit unit is called a code word
Hamming Distance Error Detection & Error Correction • Exclusive OR (XOR) is used to know the number of bits that differ between two code words • Example 10001001 10110001 00111000 • Hamming Distance is the number of bit positions in which two valid code words differ • In the above example it is 3
Code Hamming Distance Error Detection & Error Correction • With m-bit memory word, 2m words are valid (i.e. all word combinations) • With n-bit code words, only 2m out of 2n will be valid. • If an invalid code word is read out of memory, the computer knows that an error occurred • There are algorithms for computing the check bits • Using this algorithm, the set or list of valid code words could be set • Compute the hamming distance between the code words • The minimum hamming distance computed will set the
Code Hamming Distance (Cont.) Error Detection & Error Correction • With m-bit memory word, 2m words are valid (i.e. all word combinations) • With n-bit code words, only 2m out of 2n will be valid. • If an invalid code word is read out of memory, the computer knows that an error occurred • There are algorithms for computing the check bits and setting the list of valid code words • Compute the hamming distance (HD) between the code words ( two at a time) • The minimum hamming distance computed will set the Code Hamming Distance
Code Hamming Distance Properties Error Detection & Error Correction • Error-detecting and error-correcting properties of a code depends on its hamming distance • To detect d single bit errors in a code word read A distance d + 1 code is needed (minimum HD between 2 code words) • With such a code there is no way that d single-bit errors can change a valid codeword into another valid code word • To correct d single bit errors in a code word read A distance 2d + 1 code is needed (minimum HD between 2 code words) • the valid code words are so far apart that even with d changes, the original codeword is still closer than any other codeword, so it can be uniquely determined
Parity Bit (Error Detection Example) Error Detection & Error Correction • Consider the word 1011011, adding a parity bit • Even parity, to have even number of 1s 1011011 1 • Odd parity, to have odd number of 1s 1011011 0 • The code with such a parity bit will have a hamming distance of 2, as it will take 2 single bit error to move from one code word to another • With this, a single error could be detected • No errors could be corrected • When the error is detected, an error signal is set and the program will stop running
Error Correction Example Error Detection & Error Correction • Consider the following code that has only 4 valid code words 00000 00000, 00000 11111, 11111 00000, 11111 11111 • The hamming distance of the code is 5 • Single-bit errors that could be detected is 4 • Single-bit errors that could be corrected is 2 • If the code word 00000 00111 is received • If there is only a double error, then the computer knows that the value should be 00000 11111 • If there is a triple error, (the three lower ones are wrong) then the error wouldn’t be corrected
A A A error 1 0 1 1 1 1 0 0 0 0 0 1 1 B B C C 0 1 0 1 0 B C Even parity added Error in AC Error Detection for 4-bit Word Encoding of 1100 Error Detection & Error Correction
Hamming Algorithm - Idea Error Detection & Error Correction • Hamming algorithm is used to build error correcting codes for any memory word size • In a hamming code, r parity bits are added to m bit data word forming a new word of length n = m + r • The bits are numbered starting at 1 (not 0) with bit 1 the leftmost (high order) bit. • All bits whose bit numbers are a power of 2 are parity bits • All other bits are data bits
Hamming Algorithm (16-bits Example) Error Detection & Error Correction • Ex. 16-bit word • Each of the parity bits checks specific bit positions • The parity bit is set so that the number of 1s in the bit positions checked is even • Bit 1 checks bits: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21 • Bit 2 checks bits: 2, 3, 6, 7, 10, 11, 14, 15, 18, 19 • Bit 4 checks bits: 4, 5, 6, 7, 12, 13, 14, 15, 20, 21 • Bit 8 checks bits: 8, 9, 10, 11, 12, 13, 14, 15 • Bit 16 checks bits: 16, 17, 18, 19, 20, 21
Hamming Algorithm (16-bits Example) Error Detection & Error Correction • Ex. 16-bit word • Each of the parity bits checks specific bit positions • The parity bit is set so that the number of 1s in the bit positions checked is even • Bit 1 checks bits: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21 • Bit 2 checks bits: 2, 3, 6, 7, 10, 11, 14, 15, 18, 19 • Bit 4 checks bits: 4, 5, 6, 7, 12, 13, 14, 15, 20, 21 • Bit 8 checks bits: 8, 9, 10, 11, 12, 13, 14, 15 • Bit 16 checks bits: 16, 17, 18, 19, 20, 21
Hamming Algorithm (16-bits Example) Error Detection & Error Correction • Ex. 16-bit word • In general, bit b is checked by those bits b1, b2, ... bj such that b1 + b2 + ... + bj = b. • Ex. Bit 5 is checked by bits 1 and 4 1 + 4 = 5. • Ex. Bit 7 is checked by bits 1, 2 and 4 1 + 2 + 4 = 7
Hamming’s Algorithm (1 Error Example) Error Detection & Error Correction • Ex. 16-bit word = 1111 0000 1010 1110 • If bit 5 was inverted (0 instead of 1): • The 5 parity bits will be checked, with the following results: • Parity bit 1 incorrect (1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21 contain five 1’s). • Parity bit 2 correct (2, 3, 6, 7, 10, 11, 14, 15, 18, 19 contain six 1’s). • Parity bit 4 incorrect (4, 5, 6, 7, 12, 13, 14, 15, 20, 21 contain five 1’s). • Parity bit 8 correct (8, 9, 10, 11, 12, 13, 14, 15 contain two 1’s). • Parity bit 16 correct (16, 17, 18, 19, 20, 21 contain four 1’s). • Add up all incorrect parity bits 1 + 4 = 5 5 was inverted.