Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Hamming Code – Error Detection and Correction Method

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.

Hamming code is composed of,

Data Bits + Redundant Bits

(d)+(R)

Hamming code can be applied to any length of data and use the relationship between
the data (message) and the redundant bits.

7 data bits + 4 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.

The representation and the position of the 11 bits is shown below.

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?

Determining the number of redundancy bits and its position

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.

2p must be equal to or greater than d + p + 1


2p ≥ d + p +1

To detect errors in a 7 bit code, 4 redundant bits are required.


Construction of Hamming codes:
Now, the next task is to determine the positions at which these redundancy bits will be
placed within the data unit.
• or example in case of 7 bit data, 4 redundancy bits are required, so making total
number of bits as 11. The redundancy bits are placed in position 1, 2, 4 and 8 as
shown in fig.

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.

Message transmitted by the sender – 1100110

Message received by the sender – 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

So Wrong parity is at position 1 and 4

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.

Error Corrected Message

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.

You might also like