Professional Documents
Culture Documents
Hamming Code Numericals
Hamming Code Numericals
Hamming code is technique developed by R.W. Hamming for error correction. This
method corrects the error by finding the state at which the error has occurred. To correct the
error in data frame, the receiver must know exactly which bit in the frame is corrupted. To
locate the bit in error, redundant bits are used as parity bits for error detection.
(d)+(R)
Hamming code can be applied to any length of data and use the relationship between
the data (message) and the redundant bits.
Generally the linear block codes can be represented in two forms. One is called
Systematic form and other is called non-Systematic form. In Systematic Coding, the
redundant bits are calculated from the message bits and both are concatenated side by side.
Just by looking at the codeword you can identify the message portion and the redundant
portion. For example if I have the following (7,4) code, let’s say 1010111 (this is not a
Hamming code, just used for illustration), and I say that it is represented in a systematic form.
Then you can easily identify the first 4 bits 1010 as the original message bits and the
remaining bits 111 as the redundant bits. In non-systematic codes, you cannot identify them
unless you know what type of coding method was used. It means that the positions of the
original message bits and the redundant bits are mixed.
11 10 9 8 7 6 5 4 3 2 1
D11 D10 D9 P8 D7 D6 D5 P4 D3 P2 P1
Now the question is, how is the exact number of redundancy bits required to be
embedded with the particular data unit calculated?
In d+p bit codeword, there is possibility that the p bits themselves may get corrupted.
So the number of p bits used must inform about d+p bit locations plus no-error information,
i.e. d+p+1.
Consider transmitting 4 data bits and these data bits are represented by letter D. We are
going to find the 3 redundant bits (represented by letter P) using Hamming code algorithm
and form the 7 bit Hamming code. The codewords made in this way is called (7,4) Hamming
code which is a very basic code.
Let the codeword bits be represented by D7,D6,D5,P4,D3,P2,P1 Here, D7, D6, D5 and
D3 are the message bits and P4,P2,P1 are the parity or redundant bits.
The following table illustrates how to calculate parity bits for the above coding scheme.
P1 -> 1, 3, 5, 7
P2 -> 2, 3, 6, 7
P4 -> 4, 5, 6, 7
Let us attempt to find the Hamming code for the message bits 1101. The
message 1101 will be sent as 1100110 using Hamming coding algorithm as follows. Here the
data bits and the parity bits in the codeword are mixed in position and so it is a non-
systematic code.
The message send by the sender will be 1100110
Single bit Error Correction
Consider that the codeword generated as before was transmitted and instead of
receiving 1100110, we received 1110110.
A one bit error has occurred during the reception of the codeword. Let’s see how the
decoding algorithm corrects this single bit error.
Received Message
7 6 5 4 3 2 1
1 1 1 0 1 1 0
P1 -> 1, 3, 5, 7 -> Checks position on 3,5,7 and calculate the parity bit – 1 -> wrong parity
P2 -> 2, 3, 6, 7 -> Checks position on 3,6,7 and calculate the parity bit – 1 -> right parity
P4 -> 4, 5, 6, 7 -> checks position on 5,6,7 and calculates the parity bit – 1 -> wrong parity
When added 1 + 4 will give 5. Hence, the error is at the 5th position. So the 5th
position error can be corrected. 1 is changes to 0.
7 6 5 4 3 2 1
1 1 0 0 1 1 0
Practice Questions
1. Calculate the number of redundancy bits r required to correct n bits of data. Apply your result for
the case n = 15.
2. Use the Hamming code to calculate the codeword for 10011010. Explain each stage in your
calculation.
3. Use the Hamming code to calculate the codeword for 10011010. Assume that instead of
011100101010 the receiver got 011100101110. Show how the receiver can calculate which bit was
wrong and correct it.
4. Test if code word 010101100011 is correct, assuming it was created using an even parity
Hamming code. If it is incorrect, indicate what the correct code word should have been. Finally,
indicate what the original data was.