0% found this document useful (0 votes)
37 views

Hamming Error-Correction Codes: Allen D. Holliday February 17, 1994 (Revised June 15, 2002 March 1, 2004)

This document summarizes Hamming error-correction codes, which can detect and correct errors in transmitted messages. It explains parity checking as a basic error detection method, and how Hamming codes extend this by using multiple check bits assigned to overlapping data bit groups. A specific 7-bit Hamming code that can correct single-bit errors is then described, showing how each check and data bit is assigned to bit positions and check groups to enable error detection and correction.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Hamming Error-Correction Codes: Allen D. Holliday February 17, 1994 (Revised June 15, 2002 March 1, 2004)

This document summarizes Hamming error-correction codes, which can detect and correct errors in transmitted messages. It explains parity checking as a basic error detection method, and how Hamming codes extend this by using multiple check bits assigned to overlapping data bit groups. A specific 7-bit Hamming code that can correct single-bit errors is then described, showing how each check and data bit is assigned to bit positions and check groups to enable error detection and correction.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Hamming Error-Correction Codes

Allen D. Holliday
February 17, 1994 (revised June 15, 2002; March 1, 2004)

Introduction
Messages that are transmitted over a communication channel can be damaged; their bits can be
masked or inverted by noise. Detecting and correcting these errors is important. Some simple
codes can detect but not correct errors; others can detect and correct one or more errors. This
paper addresses one Hamming code that can correct a single-bit error and detect a double-bit
error. Other Hamming codes are more powerful, but beyond the scope of this paper.

Parity Checking
One simple way to detect errors is:
1. Count the number of ones in the binary message.
2. Append one more bit, called the parity bit, to the message
3. Set the parity bit to either 0 or 1, so that the number of ones in the result is even. For
example, if the original message contained 17 ones, the parity bit would be a one; if there
had been 16 ones, the parity bit would be a zero.
4. Count the number of ones in the received message, including the parity bit. The result
will always be even if no errors were encountered. (This approach also works if the parity
bit is set to make the count come out odd, as long as the receiver checks for an odd
count.)
This simple check does have two limitations: it only detects errors, without being able to correct
them; and it can’t detect errors that invert an even number of bits.

Hamming Code Approach


Hamming codes are an extension of this simple method that can used to detect and correct a
larger set of errors. The basic idea is to have several parity bits (called check bits in Hamming
codes) and assign different bits to several overlapping groups. If some parity bits are correct and
others are not, the bit in error can be deduced.
A very simple example may help to understand this approach. Suppose that the original message
is four bits long, numbered from 1 to 4. Then add three check bits as follows:
• Check bit 1 establishes even parity over itself and data bits 1 and 2 (the first two)
• Check bit 2 establishes even parity over itself and data bits 1 and 3 (the odd-numbered
bits)
• Check bit 3 establishes even parity over itself and data bits 2 and 4 (the odd-numbered
bits)
Assuming that only one bit can be in error, it can be determined with the following table:
Check bits in error Data bit in error
None None
1 and 2 1 (odd-numbered bit of the first two)
1 and 3 2 (even-numbered bit of the first two)
2 only 3 (odd-numbered bit of the second two)
3 only 4 (even-numbered bit of the second two)
Although this code works, it’s fairly inefficient; there are almost as many check bits as data bits.
Hamming Single-bit Correction Code
The Hamming single-bit correction code is implemented by adding check bits to the output
message according to the following pattern:
1) The message bits are numbered from left to right, starting at 1.
2) Every bit whose number is a power of 2 (bits 1, 2, 4, 8,…) is a check bit.
3) The other output message bits (bits 3, 5, 6, 7, 9,…) contain the data bits, in order.
Each check bit establishes even parity over itself and a group of data bits. A data bit is in a check
bit’s group if the binary representation of the data bit’s number contains a 1 in the position of the
check bit’s weight. For instance, the data bits associated with check bit 2 are all those with a 1 in
the 2’s position of their binary bit number—bits 2, 3, 6, 7, and so forth. The following diagram,
which is for an 8-bit data message, illustrates this. It shows the assignment of data bits and check
bits to the bits of a12-bit output message. The horizontal lines below the output message box
have dots to indicate the assignment of output bits to check groups. Each check group has a ones
count box, with a parity bit that is inserted into the output message.

Data bits: 1 2 3 4 5 6 7 8

Message
bits: 1 2 3 4 5 6 7 8 9 10 11 12
Check Ones
group count
8 Parity bit

4 Parity bit

2 Parity bit

1 Parity bit

(Parity bit makes


count even)

The table on the next page shows the assignment of each output message bit in messages up to
32 data bits long.
Each row contains:
• The output message bit’s number in decimal and binary.
• A check bit indicator and number, or a data bit indicator and number. Check bits are
those with only a single 1 in their binary bit number.
• Indicators of the check groups that the output message bit is a member of. There are X’s
in the columns that correspond to the Binary number weight columns with 1’s in them.
Output Message Bit Assignment Check Group Membership
Binary, with
bit position weights
Decimal 32 16 8 4 2 1 Check Data 1 2 4 8 16 32
1 0 0 0 0 0 1 C1 X
2 0 0 0 0 1 0 C2 X
3 0 0 0 0 1 1 D1 X X
4 0 0 0 1 0 0 C3 X
5 0 0 0 1 0 1 D2 X X
6 0 0 0 1 1 0 D3 X X
7 0 0 0 1 1 1 D4 X X X
8 0 0 1 0 0 0 C4 X
9 0 0 1 0 0 1 D5 X X
10 0 0 1 0 1 0 D6 X X
11 0 0 1 0 1 1 D7 X X X
12 0 0 1 1 0 0 D8 X X
13 0 0 1 1 0 1 D9 X X X
14 0 0 1 1 1 0 D10 X X X
15 0 0 1 1 1 1 D11 X X X X
16 0 1 0 0 0 0 C5 X
17 0 1 0 0 0 1 D12 X X
18 0 1 0 0 1 0 D13 X X
19 0 1 0 0 1 1 D14 X X X
20 0 1 0 1 0 0 D15 X X
21 0 1 0 1 0 1 D16 X X X
22 0 1 0 1 1 0 D17 X X X
23 0 1 0 1 1 1 D18 X X X X
24 0 1 1 0 0 0 D19 X X
25 0 1 1 0 0 1 D20 X X X
26 0 1 1 0 1 0 D21 X X X
27 0 1 1 0 1 1 D22 X X X X
28 0 1 1 1 0 0 D23 X X X
29 0 1 1 1 0 1 D24 X X X X
30 0 1 1 1 1 0 D25 X X X X
31 0 1 1 1 1 1 D26 X X X X X
32 1 0 0 0 0 0 C6 X
33 1 0 0 0 0 1 D27 X X
34 1 0 0 0 1 0 D28 X X
35 1 0 0 0 1 1 D29 X X X
36 1 0 0 1 0 0 D30 X X
37 1 0 0 1 0 1 D31 X X X
38 1 0 0 1 1 0 D32 X X X
Transmitting
Before transmission, even parity is established over each check bit and its associated data bits. In
the example below, the data bits have been copied into their proper positions in the output
message and the number of ones in each check group has been calculated. Check bits 2 and 8
have been set to 1 to make the parity count even; check bits 1 and 4 are 0, since their group’s
parity count is already even.

Data bits: 1 0 1 0 1 1 0 1

Message
bits: 0 1 1 0 0 1 0 1 1 1 0 1
Check Ones
group count
8 3 Parity bit

4 2 Parity bit

2 3 Parity bit

1 2 Parity bit

(Parity bit makes


count even)

Receiving
When the transmitted message is received, a parity bit is calculated over each group of bits (data
and parity) and stored in a syndrome value from right to left. Parity for check bit 1 and its
associated bits are rightmost in the syndrome value, parity for check bit 2 and its associated bits
are to the left, then parity for check bit 4, and so forth. If the syndrome value is 0, there have
been no errors. For single bit errors, the syndrome value identifies the erroneous bit, which needs
to be inverted.
The following diagram, which uses the output message from the Transmitting example above,
shows this process. In this example, one bit in the output message—number 6, in the dark box—
has been inverted because of a transmission error. When the ones counts for the check groups are
calculated, groups 2 and 4 have odd counts, so a 1 is placed in their positions in the syndrome
word. The resulting syndrome value is 6, which is the erroneous bits number. Inverting that bit
restores it to its transmitted value. The data bits are extracted from the received message and can
be seen to be the original values.

Check Ones
group count
8 4 Syndrome bit

4 1 Syndrome bit

2 3 Syndrome bit

1 2 Syndrome bit

(Syndrome bit
is count LSB)
0 1 1 0 0 0 0 1 1 1 0 1 0 1 1 0
(Bit 6 is in error)

0 1 1 0 0 1 0 1 1 1 0 1

Data bits: 1 0 1 0 1 1 0 1
Extensions and Limitations
The preceding scheme handles only single-bit errors—two or more errors will cause an incorrect
syndrome value. To deal with this problem, another check bit can be added to establish even
parity over all other output bits, data and check. An even number of bit errors can now be
detected (but not corrected), resulting in these cases:
Syndrome Value Message Parity Result
Zero Even No error in message
Nonzero Odd Correctable single-bit error
Nonzero Even Uncorrectable even-number-of-bits error

Odd-number-of-bits errors beyond 1 bit (3, 5, 7,...) still won’t be handled correctly. The
syndrome value and the new parity check will both indicate an error, as in case 2. Since the
syndrome value can’t point to more than one erroneous bit, the correction made will be
insufficient.
Note, however, that single and double bit errors are handled properly.

You might also like