Unit10 - Hamming Code With Exercises Conditionals
Unit10 - Hamming Code With Exercises Conditionals
As we saw with Huffman Code, all it takes is for one bit to be wrong and you have garbage.
To help counteract that problem, you need some way to detect that there is something
wrong. The most common is to use a parity bit. A parity bit is a single bit that is added to the
data stream to let you know if there has been an odd bit error, that is, an error has occurred
in an ODD number of bits. If the error has occurred in an EVEN number of bits, the parity bit
will not catch it. Let’s look at an example:
Parity, in itself, is either ODD or EVEN. What the means is that if I’m using odd parity, there
are an ODD number of one’s in the entire data steam, including the parity bit:
101111011011
Parity bit
If I’m using even parity, there are an EVEN number of one’s in the entire data stream,
including the parity bit.
001111011011
Parity bit
I’m going to take the ODD PARITY data stream and introduce an odd number of errors (3):
Correct Stream:
101111011011
Parity bit
101110101011
Parity bit
If you notice, there are now an EVEN number of one’s. Since I’m using ODD parity, I know
there is an error in my data stream.
Let’s take the same data stream and introduce an even number of errors (2):
Correct Stream:
101111011011
Parity bit
86
UNIT 10 – Hamming Code/Catch That Error and Correct It
101111101011
Parity bit
As you can see, there are still an odd number of one’s in the data stream, so the error is not
picked up by the simple parity bit. What’s more, even if we knew there was an error, there is
not way to correct it and thus we would be getting garbage.
In order to take care of that problem, there have been error detection and correction
techniques developed. One of the most common, and the one we will use here, is Hamming
Code, developed by Richard Hamming. While used primarily in telecommunications, it also
has use in those cases where accuracy of the data is of utmost importance.
Hamming Code
First of all, Hamming Code is always EVEN parity. Hamming Code detects and corrects
single bit errors. Hamming Code uses check bits and data bits. Below is a Hamming
pattern similar to what we will use. Bits 1, 2, 4, and 8 are CHECK BITS. Bits 3, 5, 6, 7, 9, 10,
11, 12 are data bits. We are using a 12-bit Hamming pattern because it lends itself well to
translation to hex (into what we call Hamming Triplets or Hamming Hex) and the problem
that arises with long data-streams - you are more apt to get multiple-bit errors, which
Hamming Code can’t correct.
DATA BITS
___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___ ___
1 2 3 4 5 6 7 8 9 10 11 12
CHECK BITS
In Hamming Code, the check bits verify the data bits in concert with the other check
bits. The check bits, if you notice, are powers of 2 (20 = 1, 21 = 2, 22 = 4, 23 = 8, 24 =
16, and so on).
So, to build a chart of check bits and the data bits they verify in concert with the other
check bits, starting with Check Bit 1, we get the following:
Data Bit 3 (1+2)
Data Bit 5 (1+4)
Data Bit 7 (1+2+4)
Data Bit 9 (1+8)
Data Bit 11 (1+2+8)
In other words, we have all the odd-numbered data bits.
87
UNIT 10 – Hamming Code/Catch That Error and Correct It
1 3 5 7 9 11
2 3 6 7 10 11
4 5 6 7 12
8 9 10 11 12
Please note that all the data bits are verified by two or more check bits.
Let’s show how you develop a Hamming Code using the Huffman Hex that we had for
our first message:
We take our first Huffman Couplet, OE, and convert it back to binary - 00001110
We then take that binary pattern, which represents data and we place it into the data
bit locations in the Huffman pattern, left to right:
___ ___ _0_ ___ _0_ _0_ _0_ ___ _1_ _1_ _1_ _0_
1 2 3 4 5 6 7 8 9 10 11 12
CHECK BITS
88
UNIT 10 – Hamming Code/Catch That Error and Correct It
We now need to set the Check Bits. Remember that Hamming is ALWAYS EVEN
parity.
Looking at Check Bit 1 and its Data Bits (3, 5, 7, 9, 11), we find that there are two
one’s (in 9 and 11). Therefore, the pattern is already even parity, so we need to set
Check Bit 1 to zero to maintain even parity over the entire pattern (including the
check bit).
_0_ ___ _0_ ___ _0_ _0_ _0_ ___ _1_ _1_ _1_ _0_
1 2 3 4 5 6 7 8 9 10 11 12
Looking at Check Bit 2 and its Data Bits (3, 6, 7, 10, 11), we find that there are two
one’s (in 9 and 11). Therefore, the pattern is already even parity, so we need to set
Check Bit 2 to zero to maintain even parity over the entire pattern (including the check
bit).
_0_ _0_ _0_ ___ _0_ _0_ _0_ ___ _1_ _1_ _1_ _0_
1 2 3 4 5 6 7 8 9 10 11 12
_0_ _0_ _0_ _0_ _0_ _0_ _0_ ___ _1_ _1_ _1_ _0_
1 2 3 4 5 6 7 8 9 10 11 12
89
UNIT 10 – Hamming Code/Catch That Error and Correct It
Looking at Check Bit 8 and its Data Bits (9, 10, 11, 12), we find that there are three
one’s (in 9, 10, and 11). Therefore, the pattern is ODD parity, so we need to set
Check Bit 8 to one to put the entire pattern (including the check bit) into EVEN parity.
_0_ _0_ _0_ _0_ _0_ _0_ _0_ _1_ _1_ _1_ _1_ _0_
1 2 3 4 5 6 7 8 9 10 11 12
0 1 E
_0_ _0_ _0_ _0_ _0_ _0_ _0_ _1_ _1_ _1_ _1_ _0_
1 2 3 4 5 6 7 8 9 10 11 12
So, our Huffman Hex of 0E becomes 01E in Hamming. If we were writing it, it would
be 0E ➔ 01E. Please note that it is NOT 0E = 01E because they are NOT equal. OE
yields 01E.
If you’re still hanging in there, let’s now see how we use Hamming Codes to detect
and correct single bit errors.
Let’s use the Hamming Hex we have done 01E. First, we translate it back into binary -
000000011110 - and put it back into the Huffman pattern
_0_ _0_ _0_ _0_ _0_ _0_ _0_ _1_ _1_ _1_ _1_ _0_
1 2 3 4 5 6 7 8 9 10 11 12
We now evaluate the Check Bits and their patterns WITH the Check Bit.
Looking at Check Bit 1 and its Data Bits (3, 5, 7, 9, 11), we find that there are two one’s (in 9
and 11). Therefore, the pattern is even parity, there is no error.
Looking at Check Bit 2 and its Data Bits (3, 6, 7, 10, 11), we find that there are two one’s (in 9
and 11). Therefore, the pattern is even parity, there is no error.
Looking at Check Bit 4 and its Data Bits (5, 6, 7,12), we find that there are no one’s.
Therefore, the pattern is even parity, there is no error.
Looking at Check Bit 8 and its Data Bits (9, 10, 11, 12), we find that there are four one’s (in 8,
9, 10, and 11). Therefore, the pattern is even parity and there is no error.
We strip out the Check Bits (1, 2, 4, 8), leaving just the Data Bits (3, 5, 6, 7, 9, 10, 11, 12),
which is our original data pattern 0E:
90
UNIT 10 – Hamming Code/Catch That Error and Correct It
00001110
That is all fine and good, but how does Hamming detect and correct single bit errors?
Let’s look at the original Hamming 01E. Instead of receiving that hex, we received
01F. We don’t know that there is a single bit error. We need to use Hamming to find
and correct it.
When we translate 01F into binary, we get 000000011111. We put it into the
Hamming pattern:
_0_ _0_ _0_ _0_ _0_ _0_ _0_ _1_ _1_ _1_ _1_ _1_
1 2 3 4 5 6 7 8 9 10 11 12
Looking at Check Bit 1 and its Data Bits (3, 5, 7, 9, 11), we find that there are two
one’s (in 9 and 11). Therefore, the pattern is even parity, there is no error.
Looking at Check Bit 2 and its Data Bits (3, 6, 7, 10, 11), we find that there are two
one’s (in 9 and 11). Therefore, the pattern is even parity, there is no error.
Looking at Check Bit 4 and its Data Bits (5, 6, 7,12), we find that there is a one (in 12).
Therefore, the pattern is odd parity, there is an error.
Looking at Check Bit 8 and its Data Bits (9, 10, 11, 12), we find that there five one’s (in
8, 9, 10, 11, and 12). Therefore, the pattern is odd parity and there is an error.
We know that Data Bits 5, 7, 9, and 11 are OK because they were verified by Check
Bit 1. We know that Data Bits 6, 7, 10, and 11 are OK because they were verified by
Check Bit 2. Outside of the Check Bits themselves (4 and 8), the only bit that hasn’t
been verified is Data Bit 12. It must be the Bit in error. Whatever it is, INVERT it (here
going from 1 to 0), so that now we have:
_0_ _0_ _0_ _0_ _0_ _0_ _0_ _1_ _1_ _1_ _1_ _0_
1 2 3 4 5 6 7 8 9 10 11 12
We strip out the Check Bits (1, 2, 4, 8), leaving just the Data Bits (3, 5, 6, 7, 9, 10, 11,
12), which is our original data pattern 0E:
00001110
Now that we’ve taken the long way to detect and correct the error, let’s look at the
shortcut. In the problem we had, 01F, we found that the patterns for Check Bits 4 and
8 were odd parity, and Therefore, had an error. What really happens is that the value
of the Check Bits (here 4 and 8) are added (giving 12) and THAT Data Bit (12) is
inverted. For example, if the patterns for Check Bits 1, 2, and 4 are odd parity, then
Data Bit 7 (1+2+4) must be in error and is inverted
91
UNIT 10 – Hamming Code/Catch That Error and Correct It
VOCABULARY
TECHNICAL NON-TECHNICAL
check bit - контрольний біт; correct (v) – виправляти; исправлять
контрольный бит (поиска);
проверочный разряд
data bit - біт даних; группа detect (v) – виявити; обнаруживать
информационных бит, определяющих
символ в асинхронной передаче данных
(В понятие информационный бит не входят
биты, содержащие управляющую
информацию, например, стартовый бит.)
even parity – парність; (контроль на) error – помилка; ошибка
чётность
odd parity - непарне співвідношення; maintain (v) – підтримувати; оказывать
отрицательная чётность (то же, что и поддержку
нечётность)
parity - рівність; паритет; pattern (n) – зразок; образец
равноправность; функциональная
совместимость; чётность
parity bit - біт парності; бит проверки
на чётность
plaintext - простий текст; простой
текст; незашифрованный текст;
открытый текст
single bit - один біт; одиночный бит;
одиночный разряд; одноразрядный
ACTIVITES:
1. Convert the remaining Huffman Hex patterns (41x, 10x, AE, 80x) into
Hamming Code.
92
UNIT 10 – Hamming Code/Catch That Error and Correct It
Vocabulary exercises
Exercise 2. Fill in the blanks with the words/phrases from the Unit.
1) Patience is the _________ most important quality needed for this job.
2) The computer costs quite a bit to __________________.
3) Investigators said
the plane crash was caused by computer error rather than human failure.
4) We are also concerned about the individual in possession of an encrypted
hard drive who refuses to hand over _________________________ .
5) It is difficult to discern any _______________ in these figures.
93
UNIT 10 – Hamming Code/Catch That Error and Correct It
Grammar
Exercise 3. Focus on the Conditionals. Study the tables below and make
sentences of your own.
If-close Main clause Use
(hypothesis) (result clause)
Type 0 if/when + present present simple something which
General truth simple is always true
or scientific
fact
e.g. If/When ice melts, it turns into Your own example
water.
94
UNIT 10 – Hamming Code/Catch That Error and Correct It
Mixed Conditionals
We can mix type 2 and type 3 conditionals
95