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

Unit10 - Hamming Code With Exercises Conditionals

The document discusses Hamming codes, which are used to detect and correct single-bit errors in data transmission. It explains that Hamming codes work by adding check bits that verify groups of data bits. This allows the detection of errors by checking if the check bit patterns are even or odd parity. For error correction, if a check detects an error, the location of the error can be determined and corrected by flipping the appropriate data bit. An example shows how a data string is encoded into a Hamming code and how single-bit errors can be detected and corrected through analysis of the check bit patterns.

Uploaded by

Asdafa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Unit10 - Hamming Code With Exercises Conditionals

The document discusses Hamming codes, which are used to detect and correct single-bit errors in data transmission. It explains that Hamming codes work by adding check bits that verify groups of data bits. This allows the detection of errors by checking if the check bit patterns are even or odd parity. For error correction, if a check detects an error, the location of the error can be determined and corrected by flipping the appropriate data bit. An example shows how a data string is encoded into a Hamming code and how single-bit errors can be detected and corrected through analysis of the check bit patterns.

Uploaded by

Asdafa
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

UNIT 10 - Hamming Code/Catch That Error and Correct It

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

Stream with Errors: Bits in Error

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

Stream with Errors: Bits in Error

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

Looking at Check Bit 2, we get the following:


Data Bit 3 (2+1)
Data Bit 6 (2+4)
Data Bit 7 (2+1+4)
Data Bit 10 (2+8)
Data Bit 11 (2+1+8)

Looking at Check Bit 4, we get the following:


Data Bit 5 (4+1)
Data Bit 6 (4+2)
Data Bit 7 (4+1+2)
Data Bit 12 (4+8)

Looking at Check Bit 8, we get the following:


Data Bit 9 (8+1)
Data Bit 10 (8+2)
Data Bit 11 (8+1+2)
Data Bit 12 (8+4)

Looking at a full chart we have:

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:

0E 41x 10x 80x

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

CHECK BIT 1 set to 0

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

CHECK BIT 2 set to 0


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 already even parity (no one’s is considered even parity), so
we need to set Check Bit 4 to zero to maintain even parity over the entire pattern
(including the check bit).

_0_ _0_ _0_ _0_ _0_ _0_ _0_ ___ _1_ _1_ _1_ _0_
1 2 3 4 5 6 7 8 9 10 11 12

CHECK BIT 4 set to 0

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

CHECK BIT 8 set to 1


Just as with Huffman Codes, we group them by four bits and convert to hex:

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

As we did before, we check the patterns with the Check Bits.

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.

2. Develop a Huffman Tree with a Character Set of at least 10 characters (plus


SPACE, ETX, and STX) that will be used in exercises for this unit.

3. Give your CHARACTER SET WITH FREQUENCIES to other group(s) to use


for activities #4 and #5.

4. Come up with a message in plaintext, convert to Huffman then to Hamming.


Give your PLAINTEXT to another group to convert to Hamming Code.

5. Come up with a message in plaintext, convert to Huffman then to Hamming.


Give your HAMMING CODE to another group to convert back to plaintext.

92
UNIT 10 – Hamming Code/Catch That Error and Correct It

Vocabulary exercises

Exercise 1. Match the word; phrase with its definition


1) single a) a particular way in which something is done or organized, or in
which something happens
2) check b) to keep a road, machine, building, etc. in good condition
3) bit c) a mistake, esp. in a way that can be discovered as wrong, or the
making of such mistakes
4) data d) to notice something that is partly hidden or not clear, or
to discover something, especially using a special method or
equipment
5) correct e) to show or fix what is wrong; make right
6) detect f) information, especially facts or numbers, collected to
be examined and considered and used to help decision-
making, or information in an electronic form that can be
stored and used by a computer
7) error g) a unit of information in a computer that must be either 0 or 1
8) maintain h) to look at or give your attention to something to get information,
often to help you decide if something is correct, safe,
or suitable
9) pattern i) considered by itself or separate from other things

Exercise 2. Fill in the blanks with the words/phrases from the Unit.

single maintain error plain text pattern detect

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.

6) In the future, cars equipped with on-board computers will be able to


________________ and avoid traffic jams automatically.

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.

Type 1 if + any present form future; imperative something likely to


Real in the (present simple, /can /may/ might/ happen in the
present/ present continuous or must/ should + present or the
future present perfect) bare infinitive/ future
present simple
e.g. If I finish my homework early, I will Your own example
take a stroll.

Type 2 If + past simple or past would/could/might Imaginary


Unreal in the continuous + bare infinitive situation contrary
present or to facts in the
advice present: also used
to give advice
e.g. If we won a lottery, we would Your own example
travel round the world. (but we don’t
have money – untrue in the present)

Type 3 If + past perfect or past would/could/migh Imaginary situation


Unreal in the perfect continuous t/ + have + past contrary to facts in
past participle the past; also used
to express regrets
or criticism
e.g. If you had studied harder, you Your own example
would not have failed the exam.

94
UNIT 10 – Hamming Code/Catch That Error and Correct It

Mixed Conditionals
We can mix type 2 and type 3 conditionals

If-clause Main clause

Type If I were you, I would have studied harder. Type


2 3
(you are not me, so you didn’t study enough.)

Type If he had saved his money, he would be going on Type


3 vacations. 2
(he did not save his money,
so he is not going on
vacation.)

Your own examples

95

You might also like