In: Computer Science
Differentiate between parity code and hamming code with examples
When we transmit data over a channel it is always susceptible to getting changed due to noise. So we need some method that can help us to detect these changes in bits.
Here comes in the Parity codes. Here we place an extra bit at the end of each data stream. This bit can be a 1 or a 0. We can work with an even parity or an odd parity. The parity here means the no. of one's. If after adding the parity bit we want no. of 1's to be even then it is called even parity else it is called odd parity. The sender and the receiver both know the type of parity used for the transmission. If there is a change in the parity then the receiver will know that there is an error. But there is no method to find out where the error is, also if there is an error in an even no. of bits then the error will go undetected. For this, we can use 2d parities, but still, there are cases where the errors may get undetected.
Eg. of an even parity:-
The data string:- 01101101.
The total message with even parity that will be transmitted 011011011.
for Odd parity, the message would have been 011011010.
Now Hamming codes are a combination of parity bits which can help us to detect which bits got flipped & then we can correct them. Hamming codes are a family of linear error-correcting codes. They can detect up to 2-bit errors or correct 1-bit errors. In the hamming code, we place some redundant bits for the purpose of detecting errors.
For a 7 bit no. there will be 4 redundant bits which give a total of 11 bits message.
Let the message be 1011001.
11 | 10 | 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 |
D7 | D6 | D5 | R8 | D4 | D3 | D2 | R4 | D1 | R2 | R1 |
The first line represents the bits locations, the R shows the redundant terms. Now we already know the data bits, we only need to determine the parity bits.
R1 will check the parity with all those bits whose positions binary representation includes a 1 in LSB. Here, 1, 3, 5, 7, 9, 11
R2 will check the parity with all those bits whose positions binary representation includes a 1 in the second position from the LSB. Here, 2, 3, 6, 7, 10, 11
R4 will check the parity with all those bits whose positions binary representation includes a 1 in the third position from the LSB. Here, 4-7.
R8 will check the parity with all those bits whose positions binary representation includes a 1 in the fourth position from the LSB. Here, 8-15
For even parity the bits will
R1 = 0; R2 = 1; R4 = 1; R8 = 0.
So the data to be transferred will be 10101001110.
Now similarly the receiver can check the parity in same manner and check for errors.
Hope this helps. If you have any queries or suggestions regarding the answers please leave them in the comments section so I can update and improve the answer. Thank you.