Binary Code and Error Detection
Binary Code and Error Detection
Part – II
Binary codes, Error detecting &
correcting codes
3/25/2023 1
Binary codes
Even though binary numbers are the most appropriate for the
internal computations of a digital system, most people still
prefer to deal with decimal numbers. As a result, the external
interfaces of a digital system may read or display decimal
numbers, and some digital devices actually process decimal
numbers directly. The human need to represent decimal
numbers doesn't change the basic nature of digital electronic
circuits- they still process signals that take on one of
only two states that we call 0 and 1. Therefore, a decimal
number is represented in a digital system by a string of bits,
where different combinations of bit values in the string
represent different decimal numbers.
3/25/2023 2
All Digital systems use some form of binary numbers for
their internal operation, but the external world is decimal in
nature. This means that conversions between the decimal
and binary systems are being performed often. We have
seen that the conversions between decimal and binary can
become long and complicated for large numbers. For this
reason, a means of encoding decimal numbers that
combines some features of both the decimal and the binary
systems is used in certain situations.
3/25/2023 3
A set of n-bit strings in which different bit strings represent
different numbers or other things is called a Code. A
particular combination of n bit-values is called a Code word.
A sequence of Binary bits which represents a decimal digit is
called a Code Word.
As we'll see in the examples of decimal codes in this section,
there may or may not be an arithmetic relationship between
the bit values in a code word and the thing that it represents.
Furthermore, a code that uses n-bit strings need not contain
𝟐𝐧 valid code words.
At least four bits are needed to represent the ten decimal
digits. There are billions and billions of different ways to
choose ten 4-bit code words, but some of the more common
decimal codes are listed in the below Table
3/25/2023 4
3/25/2023 5
Classification of Codes:
3/25/2023 6
Classification Of Binary Codes
3/25/2023 7
Weighted codes
In this code, each digit position of the number represents a
specific weight. In weighted code, each decimal digit is
represented by a group of four bits and each bit has a weight
8, 4, 2, 1. There are different Binary coded Decimal(BCD) like
8421 code, 2421 code, 3321 code, 4221 code, 5211 code
which comes under weighted code. For example, let us
consider a decimal number 25, for which the equivalent
binary number in 8421 code is as follows
3/25/2023 8
Non-weighted codes
In this code, no weight is assigned to any of the bit
positions. Bits will not have any fixed value based on their
position. Excess-3 code and Gray code are the examples of
non-weighted code.
Sequential Codes:
A sequential code is one, in which each succeeding code
word is one binary number greater than its preceding code
word. Such a code facilitates mathematical manipulation of
data.
Ex: 8421 and Excess-3 codes are sequential.
5211,2421,642-3 are not Sequential.
3/25/2023 9
3/25/2023 10
Positively-weighted and Negatively-weighted
codes:
• Positively weighted codes are those in which all
the weights assigned to the binary digits are
positive. There are only 17 positively weighted
codes.
• In every Positively weighted code, the first weight
must be 1, second weight must be 1 or 2 and the
sum of all the weights must be equal to or greater
than 9.
• Examples are 8421,2421,5211,3321,4311…..
• Negatively weighted codes are those in which
some of the weights assigned to the binary digits
are negative.
• Examples are 642-3, 631-1, 84-2,-1 and 74-2-1
3/25/2023 11
Self-Complementing Codes:
A code is said to be Self-complementing, if the code
word of the 9’s complement of N i.e., of 9-N can be
obtained from the code word of N by interchanging
all the 1’s and 0’s. For a code to be Self-
complementing, the sum of all its weights must be 9.
The code for 9 is the complement of the code for 0,
the code for 8 is the complement of the code for 1
and so on.
Ex: 2421,5211,642-3,84-2-1 and excess-3 are Self
complementing codes.
8421 and 5421 are not self-complementing.
3/25/2023 12
Only four Positively-weighted self-complementing
codes: 2421, 5211, 3321, 4311.There are 13
negatively weighted self-complementing codes.
Cyclic codes:
Cyclic codes are those in which each successive
code word differs from the preceding one in only
One-bit position. They are also known as Unit-
distance codes.
Ex: The gray code is a Cyclic code.
It is often used for translating an analog quantity
such as shaft position to digital form.
3/25/2023 13
3/25/2023 14
Reflective codes:
A reflective code is a binary code in which the n least
significant bits for code words 𝟐𝒏 through 𝟐𝒏+𝟏 − 𝟏 are
the mirror images of those for 0 through 𝟐𝒏 − 𝟏 .
Ex: The Gray code is a reflective code.
3/25/2023 15
Binary coded Decimal
3/25/2023 16
The 8421 BCD Code
3/25/2023 17
Invalid Codes
You should realize that, with four bits, sixteen numbers (0000
through 1111) can be represented but that, in the 8421 code,
only ten of these are used. The six code combinations that
are not used—1010, 1011, 1100, 1101, 1110, and 1111—are
invalid in the 8421 BCD code.
To express any decimal number in BCD, simply replace each
decimal digit with the appropriate 4-bit code.
3/25/2023 18
3/25/2023 19
It is equally easy to determine a decimal number from a BCD
number. Start at the right-most bit and break the code into
groups of four bits. Then write the decimal digit represented
by each 4-bit group.
3/25/2023 20
Applications
Digital clocks, digital thermometers,
digital meters, and other devices with
seven-segment displays typically use
BCD code to simplify the displaying of
decimal numbers. BCD is not as
efficient as straight binary for
calculations, but it is particularly
useful if only limited processing is
required, such as in a digital
thermometer.
3/25/2023 21
BCD Addition
3/25/2023 23
3/25/2023 24
3/25/2023 25
3/25/2023 26
Eg: Perform the following decimal additions in 8421 BCD
code
(a) 25 + 13 (b) 679.6 +536.8
3/25/2023 27
BCD Subtraction:
3/25/2023 28
Ex: Perform the following decimal subtractions in the 8421
BCD code.
(a) 38 – 15 (b) 206.7 – 147.8
3/25/2023 29
Comparison of BCD and Binary
It is important to realize that BCD is not another number
system like binary, decimal, and hexadecimal. In fact, it
is the decimal system with each digit encoded in its
binary equivalent. It is also important to understand that
a BCD number is not the same as a straight binary
number. A straight binary number takes the complete
decimal number and represents it in binary; the BCD
code converts each decimal digit to binary individually.
To illustrate, take the number 137 and compare its
straight binary and BCD codes:
𝟏𝟑𝟕𝟏𝟎 = 𝟏𝟎𝟎𝟏𝟏𝟎𝟏𝟏𝟏𝟐 (binary)
𝟏𝟑𝟕𝟏𝟎 = 0001 0011 0111 (BCD)
EXAMPLE 2-7
3/25/2023 30
The BCD code requires 12 bits, while the straight binary
code requires only eight bits to represent 137. BCD requires
more bits than straight binary to represent decimal numbers
of more than one digit because BCD does not use all possible
four-bit groups, as pointed out earlier, and is therefore
somewhat inefficient.
The main advantage of the BCD code is the relative ease of
converting to and from decimal. Only the four-bit code
groups for the decimal digits 0 through 9 need to be
remembered. This ease of conversion is especially important
from a hardware standpoint because in a digital system, it is
the logic circuits that perform the conversions to and from
decimal.
3/25/2023 31
Excess-3 code:
Excess-3, also called XS3, is a non-weighted code used to
express decimal numbers. It is another important binary
code. It is particularly significant for arithmetic operations
as it overcomes the shortcomings encountered while using
the 8421 BCD code to add two decimal digits whose sum
exceeds 9. This code is used in some old computers. The
Excess-3 code for a given decimal number is determined by
adding ‘3’ to each decimal digit in the given number and
then replacing each digit of the newly found decimal
number by its four bit binary equivalent.
3/25/2023 32
The table gives is the Excess-3 code. For example, XS3
code of 24 is obtained a
2 4
+3 +3
5 7
0101 0111
Thus, XS3 code of 24 is 0101 0111.
3/25/2023 33
The key feature of the Excess-3 code is, that it is self
complementing. In other words, the 1’s complement of
an Excess- 3 number is the Excess- 3 code for the 9’s
complement of the corresponding decimal number. For
example, the Excess- 3 code for decimal 6 is 1001. The
1’s complement of 1001 is 0110, which is the Excess-3
code for decimal 3, and 3 is the 9’s complement of 6.
This property of Excess-3 code makes it useful in some
arithmetic operations.
consider a few examples. The Excess-3 code
for decimal number 27
is 01011010.
)
3/25/2023 34
Similarly, Excess-3 code for (597)10 and (14.57)10 is
(597)10 = (100011001010)
(14.57)10 = (01000111.10001010)
One should note that corresponding to given Excess-3
code, the equivalent decimal number can be
determined by first splitting the number into four-bit
groups, starting from radix point and then subtracting
0011 from each four-bit group.
This gives us 8421 BCD equivalent of the given Excess-
3 code, which can then be converted into the
equivalent decimal number.
3/25/2023 35
• For example; Let us suppose we want to determine the
decimal equivalent for the Excess-3 code 1000110. First we
make group of 4 bits starting from radix point.
3/25/2023 36
XS-3 Addition:
3/25/2023 37
Ex: Perform the following additions in XS-3 code
(a) 37 + 28 (b) 247.6 + 359.4
3/25/2023 38
3/25/2023 39
XS-3 Subtraction:
3/25/2023 40
Ex: Perform the following subtractions in XS-3
code
(a) 267 – 175 (b) 57.6 – 27.8
3/25/2023 41
The Gray Code
Digital systems operate at very fast speeds and respond
to changes that occur in the digital inputs. Just as in
life, when multiple input conditions are changing at the
same time, the situation can be misinterpreted and
cause an erroneous reaction. When you look at the bits
in a binary count sequence, it is clear that there are
often several bits that must change states at the same
time.
In order to reduce the likelihood of a digital circuit
misinterpreting a changing input, the Gray code has
been developed as a way to represent a sequence of
numbers. The unique aspect of the Gray code is that
only one bit ever changes between two successive
numbers in the sequence.
3/25/2023 42
The Gray code is unweighted and is not an arithmetic
code; that is, there are no specific weights assigned to
the bit positions. The important feature of the Gray
code is that it exhibits only a single bit change from
one code word to the next in sequence. This property is
important in many applications, such as shaft position
encoders, where error susceptibility increases with the
number of bit changes between adjacent numbers in a
sequence. Gray codes are used in instrumentation and
data acquisition systems where linear or angular
displacement is measured.
3/25/2023 43
3/25/2023 44
Table is a listing of the 4-bit Gray code for decimal numbers
0 through 15. Binary numbers are shown in the table for
reference. Like binary numbers, the Gray code can have
any number of bits. Notice the single-bit change between
successive Gray code words. For instance, in going from
decimal 3 to decimal 4, the Gray code changes from 0010 to
0110, while the binary code changes from 0011 to 0100, a
change of three bits. The only bit change in the Gray code is
in the third bit from the right: the other bits remain the same.
3/25/2023 45
3/25/2023 46
Binary to Gray Code Conversion
Conversion between binary code and Gray code is sometimes
useful. The following rules explain how to convert from a
binary number to a Gray code word:
1. The most significant bit (left-most) in the Gray code is the
same as the corresponding MSB in the binary number.
2. Going from left to right, add each adjacent pair of binary
code bits to get the next Gray code bit. Discard carries. (OR)
Ex-OR adjacent bits together starting from the left of this
number.
Ex: Convert the binary number 10110 to Gray code
3/25/2023 47
Gray-to-Binary Code Conversion
To convert from Gray code to binary, use a similar
method; however, there are some differences. The
following rules apply:
1. The most significant bit (left-most) in the binary code
is the same as the corresponding bit in the Gray code.
2. Add each binary code bit generated to the Gray code
bit in the next adjacent position. Discard carries.
For example, the conversion of the Gray code word
11011 to binary is as follows:
3/25/2023 48
3/25/2023 49
To convert binary to Gray, simply start on the most
significant bit and use it as the Gray MSB as shown in Figure
(a). Now compare the MSB binary with the next binary bit
(B1). If they are the same, then G1 = 0. If they are different,
then 𝑮𝟏 = 1. 𝑮𝟎 can be found by comparing 𝑩𝟏 with 𝑩𝟎 .
Conversion from Gray code back into binary is shown in
Figure(b). Note that the MSB in Gray is always the same as
the MSB in binary. The next binary bit is found by comparing
the binary bit to the left with the corresponding Gray code
bit. Similar bits produce a 0 and differing bits produce a 1.
3/25/2023 50
(a) Binary to Gray (b) Gray to Binary
3/25/2023 51
Alphanumeric Codes
In order to communicate, you need not only numbers,
but also letters and other symbols. In the strictest
sense, alphanumeric codes are codes that represent
numbers and alphabetic characters (letters). Most such
codes, however, also represent other characters such
as symbols and various instructions necessary for
conveying information. At a minimum, an alphanumeric
code must represent 10 decimal digits and 26 letters of
the alphabet, for a total of 36 items. This number
requires six bits in each code combination because five
bits are insufficient ( 𝟐𝟓 = 𝟑𝟐 ). There are 64 total
combinations of six bits, so there are 28 unused code
combinations.
3/25/2023 52
These codes consists of symbols to represent the 26
alphabets(including capital and small letter), 0-9
numbers and other symbols. Most commonly used
alphanumeric codes are:
▪ ASCII(American Standard code for Information
Interchange) – 7 bit code
▪ EBCDIC (Extended Binary Coded Decimal Interchange
Code) – 8 bit code
▪ Hollerith code
3/25/2023 53
Obviously, in many applications, symbols other than just
numbers and letters are necessary to communicate
completely. You need spaces, periods, colons, semicolons,
question marks, etc. You also need instructions to tell the
receiving system what to do with the information. With codes
that are six bits long, you can handle decimal numbers, the
alphabet, and 28 other symbols. This should give you an idea
of the requirements for a basic alphanumeric code. The ASCII
is a common alphanumeric code
ASCII
ASCII is the abbreviation for American Standard Code for
Information Interchange. Pronounced “askee,” ASCII is a
universally accepted alphanumeric code used in most
computers and other electronic equipment.
3/25/2023 54
ASCII Code:
• Number of bit patterns in ASCII code = 𝟐𝟕 =128
• The ASCII can be used to encode both Lower case
and Upper case characters of the alphabets (52
symbols) and some special symbols and 10 decimal
digits.
• It is extensively used for printers and terminals
that interface with small computer systems.
• Characters are assigned in ascending binary
numbers, so ASCII is very easy for a computer to
alphabetize and sort.
3/25/2023 55
MSBs
LSBs
3/25/2023 56
Most computer keyboards are standardized with the ASCII.
When you enter a letter, a number, or control command, the
corresponding ASCII code goes into the computer.
ASCII has 128 characters and symbols represented by a 7-bit
binary code. Actually, ASCII can be considered an 8-bit code
with the MSB always 0. This 8-bit code is 00 through 7F in
hexadecimal. The first thirty-two ASCII characters are
nongraphic commands that are never printed or displayed
and are used only for control purposes. Examples
of the control characters are “null,” “line feed,” “start of
text,” and “escape.” The other characters are graphic
symbols that can be printed or displayed and include the
letters of the alphabet (lowercase and uppercase), the ten
decimal digits, punctuation signs, and other commonly used
symbols.
3/25/2023 57
Table below is a listing of the ASCII code showing the
decimal, hexadecimal, and binary representations for
each character and symbol. The left section of the table
lists the names of the 32 control characters (00 through
1F hexadecimal). The graphic symbols are listed in the
rest of the table (20 through 7F hexadecimal).
3/25/2023 58
3/25/2023 59
3/25/2023 60
The EBCDIC code:
• 𝟐𝟖 =256 bit patterns can be formed in this code.
• This code can be used to encode all the symbols
and control characters found in ASCII and many
other symbols too.
• Many bit patterns are unassigned.
• It is used by most large computers to communicate
in Alphanumeric data.
• Unlike ASCII which uses straight binary sequence
(Writing the numbers in Binary number system) for
representing characters, this EBCDIC code uses
BCD as the basis of binary assignment.
3/25/2023 61
3/25/2023 62
Extended ASCII Characters
In addition to the 128 standard ASCII characters, there are
an additional 128 characters that were adopted by IBM for
use in their PCs (personal computers). Because of the
popularity of the PC, these particular extended ASCII
characters are also used in applications other than PCs
and have become essentially an unofficial standard. The
extended ASCII characters are represented by an 8-bit
code series from hexadecimal 80 to hexadecimal FF and
can be grouped into the following general categories:
foreign(non-English) alphabetic characters, foreign
currency symbols, Greek letters, mathematical symbols,
drawing characters, bar graphing characters, and shading
characters.
3/25/2023 63
Error Detecting and Error Correcting codes
The movement of binary data and codes from one
location to another is the most frequent operation
performed in digital systems. Here are just a few
examples:
▪ The transmission of digitized voice over a microwave
link
▪ The storage of data in and retrieval of data from
external memory devices such as magnetic and
optical disk
▪ The transmission of digital data from a computer to a
remote computer over telephone lines (i.e., using a
modem). This is one of the major ways of sending and
receiving information on the Internet.
3/25/2023 64
Whenever information is transmitted from one device (the
transmitter) to another device (the receiver), there is a
possibility that errors can occur such that the receiver does
not receive the identical information that was sent by the
transmitter. The major cause of any transmission errors is
electrical noise, which consists of spurious fluctuations in
voltage or current that are present in all electronic systems
to varying degrees. Figure shows a simple illustration of a
type of transmission error.
3/25/2023 65
Most modern digital equipment is designed to be relatively
error-free, and the probability of errors such as the one
shown in Figure is very low. However, we must realize that
digital systems often transmit thousands, even millions, of
bits per second, so that even a very low rate of occurrence
of errors can produce an occasional error that might prove
to be bothersome, if not disastrous. For this reason, many
digital systems employ some method for detection (and
sometimes correction) of errors. One of the simplest and
most widely used schemes for error detection is the parity
method.
3/25/2023 66
Parity Method for Error Detection:
The simplest technique for detecting errors is that of adding an
Extra bit, known as Parity Bit, to each word being transmitted.
Many systems use a parity bit as a means for bit error
detection. Any group of bits contain either an even or an odd
number of 1s. A parity bit is attached to a group of bits to make
the total number of 1s in a group always even or always odd.
An even parity bit makes the total number of 1s even, and an
odd parity bit makes the total odd. A given system operates
with even or odd parity, but not both. For instance, if a system
operates with even parity, a check is made on each group of
bits received to make sure the total number of 1s in that group
is even. If there is an odd number of 1s, an error has occurred.
3/25/2023 67
Table lists the parity bits for each BCD number for both even
and odd parity. The parity bit for each BCD number is in the P
column.
3/25/2023 68
The parity bit can be attached to the code at either the
beginning or the end, depending on system design. Notice
that the total number of 1s, including the parity bit, is
always even for even parity and always odd for odd parity.
Detecting an Error
A parity bit provides for the detection of a single bit error
(or any odd number of errors, which is very unlikely) but
cannot check for two errors in one group. For instance,
let’s assume that we wish to transmit the BCD code 0101.
(Parity can be used with any number of bits; we are
using four for illustration.) The total code transmitted,
including the even parity bit, is
3/25/2023 69
When this code is received, the parity check circuitry
determines that there is only a single 1 (odd number),
when there should be an even number of 1s. Because an
even number of 1s does not appear in the code when it is
received, an error is indicated. An odd parity bit also
provides in a similar manner for the detection of a single
error in a given group of bits.
3/25/2023 70
• Odd parity is used more often because even parity does
not detect the situation where all 0s are created by
short-circuit or some other fault conditions.
• A code is an error detecting code, if and only if its
minimum distance is 2 or more. The distance between
the two words is defined as the number of digits that
must change in a word so that the other word results.
Ex: 0011 and 1010 → distance=2
0111 and 1000 → distance=4
• In even parity scheme, find the errors
a) 10101011 b) 11110110
• In odd parity scheme, find the errors
a) 10110111 b) 11101010
3/25/2023 71
3/25/2023 72
Cyclic Redundancy Check:
The cyclic redundancy check (CRC) is a widely used
code used for detecting one and two-bit transmission
errors when digital data are transferred on a
communication link.
The communication link can be between two computers
that are connected to a network or between a digital
storage device (such as a CD, DVD, or a hard drive) and a
PC. If it is properly designed, the CRC can also detect
multiple errors for a number of bits in sequence (burst
errors). In CRC, a certain number of check bits,
sometimes called a checksum, are appended to the data
bits (added to end) that are being transmitted.
3/25/2023 73
The transmitted data are tested by the receiver for errors
using the CRC. Not every possible error can be identified,
but the CRC is much more efficient than just a simple
parity check.
CRC Process:
As each word is transmitted, it is added to the sum of the
previously transmitted words, and the sum retained at
the transmitter end.
At the end of transmission, the sum called the Checksum
up to that time is sent to the receiver.
The receiver check its sum with transmitted sum. If the
two sums are same, it indicates no error.
If there is an error, the entire data has to be
retransmitted.
3/25/2023 74
CRC Process
3/25/2023 75
3/25/2023 76
Block Parity:
• When several binary words are transmitted or stored in
a succession, the collection of bits is treated as a
Block of Data, having rows and columns.
• Parity bits can then be assigned to both rows and
columns. This scheme makes it possible to correct any
single error occurring in a data word and to detect any
two errors in a word.
• The parity row is often called a Parity Word.
• Block parity technique is also called Word Parity, it is
widely used for data stored on magnetic tapes.
• At the receiving end, parity is checked both row-wise
and column wise.
3/25/2023 77
Four 7-bit code words
4 * 7 block
5 * 8 block → Add parity
row and column
3/25/2023 78
Five-bit Codes:
• Some 5-bit BCD codes that have parity contained within
each code for ease of error detection are shown.
3/25/2023 79
• The 63210 is a weighted code (except for decimal
digit 0). It has the useful error-detecting property that
there are exactly two 1s in each code group. This
code is used for storing data on magnetic tapes.
• The 2-out-of-5 code is a non-weighted code having
exactly two 1s in each code group. This code is used
in the telephone and communication industries.
• At the receiving end, the receiver can check the
number of 1s in each character received.
• The shift-counter code, also called Johnson code, has
the bit patterns produced by a 5-bit Johnson counter.
The 51111 code is similar to the Johnson code but it
is weighted.
3/25/2023 80
The Biquinary Code:
• It is a weighted 7-bit BCD code. It is a parity data
code.
• Each group consists of a 2-bit subgroup and a 5-bit
subgroup and each of these subgroups consists of
a single 1. Thus, it has the error checking feature,
for each code group has exactly two 1s and each
subgroup has exactly one 1.
• The weights of the bit positions are 50 43210.
Since there are two positions with weight 0, it is
possible to encode decimal 0 with a group
containing 1s, unlike other weighted codes.
• The biquinary code is used in the Abacus.
3/25/2023 81
3/25/2023 82
The Ring-Counter Code:
• A 10-bit ring counter code will produce a sequence
of 10-bit groups having the property that each
group has a single 1.
• It is the code obtained by assigning a decimal digit
to each of those ten patterns.
• It is a weighted code because each bit position has
a weight equal to one of the 10 decimal digits.
• Although this code is inefficient, it has an
excellent error-detecting properties and it is easier
to implement.
3/25/2023 83
Ring-Counter Code
Decimal 9 8 7 6 5 4 3 2 1 0
Digit
0 0 0 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0 1 0
2 0 0 0 0 0 0 0 1 0 0
3 0 0 0 0 0 0 1 0 0 0
4 0 0 0 0 0 1 0 0 0 0
5 0 0 0 0 1 0 0 0 0 0
6 0 0 0 1 0 0 0 0 0 0
7 0 0 1 0 0 0 0 0 0 0
8 0 1 0 0 0 0 0 0 0 0
9 1 0 0 0 0 0 0 0 0 0
3/25/2023 84
Hamming Code
3/25/2023 85
1. One of the most effective codes for error-recovery
2. Used in situations where random errors are likely to occur
3. Error detection and correction increases in proportion to
the number of parity bits (error-checking bits) added to the
end of the information bits
4. Code word = information bits + parity bits
5. Hamming distance: the number of bit positions in which two
code words differ.
6. Minimum Hamming distance or D(min) : determines its error
detecting and correcting capability.
7. Hamming codes can always detect D(min) – 1 errors, but
can only correct half of those errors.
8. A code with minimum distance of 3 cannot only correct
1-bit errors, but also detect 2-bit errors.
3/25/2023 86
Encoding the message with hamming code
Selecting the number of redundant bits
The hamming code uses the number of redundant bits
depending on the number of information bits in the message.
Let n be the number of information or data bits, then the
number of redundant bits P is determined from the following
formula,
𝟐𝑷 ≥ 𝒏 + 𝑷 + 𝟏
For example, if 4-bit information is to be transmitted, then
n=4. The number of redundant bits is determined by the trial
and error method. Let P=2, we get,
𝟐𝟐 ≥ 𝟒 + 𝟐 + 𝟏
P=2 does not satisfy the equation. P=3 satisfies the equation
so P must be equal to 3.
3/25/2023 87
In this way, the number of redundant bits is selected for
the number of information bits to be transmitted. The
redundant bits are placed at the positions that are
numbered corresponding to the power of 2, i.e., 1, 2, 4,
8,… For example, the number of data bits n=4, and the
number of redundant bits P=3. So the message consists
of 7 bits in total that are to be coded. Let the leftmost
bit be designated as bit 1, the next successive bit as bit
2 and so on.
3/25/2023 88
Bit location 1 2 3 4 5 6 7
Bit Designation 𝑃1 𝑃2 𝐷3 𝑃4 𝐷5 𝐷6 𝐷7
Binary Representation 001 010 011 100 101 110 111
Information/Data Bits 𝑚1 𝑚2 𝑚3 𝑚4
Parity Bits 𝑃1 𝑃2 𝑃3
3/25/2023 89
Parity bit P2 covers all data bits in positions whose
binary representation has 1 in the second least
significant position(010, 011, 110, 111, etc.). Thus P2
checks the bit in locations 2, 3, 6, 7, etc.
Parity bit P4 covers all data bits in positions whose
binary representation has 1 in the third least significant
position(100, 101, 110, 111, etc.). Thus P4 checks the bit
in locations 4, 5, 6, 7, etc.
Each parity bit checks the corresponding bit locations
and assign the bit value as 1 or 0, so as to make the
number of 1s as even for even parity and odd for odd
parity.
3/25/2023 90
Example problem
Encode a binary word 11001 into the even parity hamming
code.
Given number of data bits 5
To find the number of redundant bits:
The equation
𝟐𝑷 ≥ 𝒏 + 𝑷 + 𝟏
Is satisfied for P=4. So total code bits are 9. The redundant
bits are placed at bit positions 1,2,4,8.
Construct the bit location table:
3/25/2023 91
Bit Location 1 2 3 4 5 6 7 8 9
Bit Designation 𝑃1 𝑃2 𝐷3 𝑃4 𝐷5 𝐷6 𝐷7 𝑃8 𝐷9
Binary Representation 0001 00010 0011 0100 0101 0110 0111 1000 1001
Data Bits 1 1 0 0 1
Parity Bits 1 1 1 1
𝑷𝟏 𝑷𝟐 𝑫𝟑 𝑷𝟒 𝑫𝟓 𝑫𝟔 𝑫𝟕
1 1 0 1
3/25/2023 96
Example: A 7-bit hamming code is received as 1011001.
Assume Even parity and state whether the received code is
correct or wrong. If wrong, locate the bit in Error.
Solution: Received code: 1011001
1 2 3 4 5 6 7
𝑷𝟏 𝑷𝟐 𝑫𝟑 𝑷𝟒 𝑫𝟓 𝑫𝟔 𝑫𝟕
1 0 1 1 0 0 1
3/25/2023 97
Example: The message coded below in the 7-bit
hamming code is transmitted through a noisy channel.
Decode the message assuming that at most a single
error occurred in each code word.
1001001, 0111001, 1110110, 0011011
Solution: The given data is of 28 bits, split it into four
groups of 7 bits each and correct the error, in each
group and write the corrected data.
3/25/2023 98
3/25/2023 99
3/25/2023 100
The 15 bit Hamming code:
To transmit eleven data bits, four parity bits located
at positions 1,2,4,8 from left are added to make a 15-
bit code word which is then transmitted.
The word format would be as shown below.
Where the D bits are Data bits and the P-bits are
Parity bits.
P1 is to be set to a 0 or 1 so that it establishes even
parity over bits 1,3,5,7,9,11,13 and 15.
3/25/2023 101
P2 is to be set to a 0 or 1 so that it establishes even
parity over bits 2,3,6,7,10,11,14 and 15.
3/25/2023 102
3/25/2023 103
3/25/2023 104
The 12 bit Hamming code:
To transmit eight data bits, four parity bits located
at positions 1,2,4,8 from left are added to make a 12-
bit code word which is then transmitted.
The word format would be as shown below.
Where the D bits are Data bits and the P-bits are
Parity bits.
P1 is to be set to a 0 or 1 so that it establishes even
parity over bits 1,3,5,7,9 and 11.
3/25/2023 105
P2 is to be set to a 0 or 1 so that it establishes even
parity over bits 2,3,6,7,10 and 11.
3/25/2023 106
3/25/2023 107
3/25/2023 108
3/25/2023 109