HW336514
HW336514
COMPUTER ORGANIZATION
Computer Organization refers to the operational units and their interconnections that
implement the architecture specification. It deals with how the components of a
computer system are arranged and how they interact to perform the required operations.
Computer organization is concerned with the physical implementation of the
architecture design and includes decisions about the interconnection and
communication between components, such as the bus structure, memory hierarchy, and
input/output systems.
COMPUTER ARCHITECTURE
Computer architecture is a blueprint for the design of a computer system and describes
the system in an abstract manner. It describes how the computer system is designed. On
the other hand, computer organization is how operational parts of a computer system
are linked together. Computer Architecture is a functional description of
requirements and design implementation for the various parts of a computer. It deals
with the functional behavior of computer systems. It comes before the computer
organization while designing a computer.
DIGITAL SYSTEM
Digital electronics is a field of computer science. It deals with devices that are used to
carry out computer applications. In digital electronics, we use two-state or binary logic.
The two logic states are “0” (low) and “1” (high). Computer uses binary number system
for its operations. Digital electronics represents the two binary numbers, 1 and 0, using
two voltage levels in a device called a logic gate. Sometimes the two states can also be
represented using Boolean logic functions, “true” or “false” states, or using an “on” or
“off” state. Logic gates are important components of a digital circuit.
A logic gate takes two inputs and generates a single output. Basically, digital data is
represented, stored, and transmitted as groups of binary digits which are called bits. The
group of bits is known as binary code. Binary codes are used in computers as they allow
computers to perform complex calculations quickly and efficiently. Binary codes are
used in financial, commercial, and industrial applications. Binary codes can be
represented as numbers and letters of the alphabets as well as many special characters
and control functions. They are classified as numeric or alphanumeric codes. Numeric
codes are used to represent numbers, whereas alphanumeric codes are used to represent
alphabetic letters and numerals.
DATA TYPE
Computer programs or application may use different types of data based on the problem
or requirement.
Numeric data
It can be of the following two types:
• Integers
• Real Numbers
Character data
A sequence of character is called character data. A character may be alphabetic (A-Z
or a-z), numeric (0-9), special character (+, #, *, @, etc.) or combination of all of these.
A character is represented by group of bits. When set of multiple character are
combined together they form a meaningful data. A character is represented in standard
ASCII format.Another popular format is EBCDIC used in large computer systems.
Logical data
A logical data is used by computer systems to take logical decisions. Logical data is
different from numeric or alphanumeric data in the way that numeric and alphanumeric
data may be associated with numbers or characters but logical data is denoted by either
of two values true (T) or false(F). You can see the example of logical data in
construction of truth table in logic gates. A logical data can also be statement consisting
of numeric or character data with relational symbols (>, <, =, etc.).
Character set
Character sets can of following types in computers:
• Alphabetic characters- It consists of alphabet characters A-Z or a-z.
• Numeric characters- It consists of digits from 0 to 9.
• Special characters- Special symbols are +, *, /, -, ., <, >, =, @, %, #, etc.
NUMBER SYSTEM
A computer can understand only a few symbols called digits and these symbols describe
different values depending on the position they hold in the number. In general, the
binary number system is used in computers. However, the octal, decimal and
hexadecimal systems are also used sometimes. The number system is simply a system
to represent or express numbers. There are various types of number systems and the
most commonly used ones are decimal number system, binary number system, octal
number system, and hexadecimal number system. The number system helps to
represent numbers in a small symbol set. Computers, in general, use binary numbers 0
and 1 to keep the calculations simple and to keep the amount of necessary circuitry less,
which results in the least amount of space, energy consumption and cost.
Digital and Electronic systems may use various number systems like Decimal,
Hexadecimal, Octal, and Binary. We can write a number N in base or radix b as:
Nb = dn-1 dn-2 -- -- -- -- d1 d0 . d-1 d-2 -- -- -- -- d-m
Here, dn-1 to d0 is the integer part, follows a radix point, and d-1 to d-m is the fractional
part.
dn-1 is the Most significant bit (MSB)
d-m is the Least significant bit (LSB)
A computer can understand only the “on” and “off” state of a switch. These two
states are represented by 1 and 0. The combination of 1 and 0 form binary
numbers. These numbers represent various data. As two digits are used to
represent numbers, it is called a binary or base 2 number system. The binary
number system uses positional notation. But in this case, each digit is multiplied
by the appropriate power of two based on its position.
This system uses digits 0 to 7 (i.e. 8 digits) to represent a number and the
numbers are as a base of 8.
In this system, 16 digits used to represent a given number. Thus it is also known
as the base 16 number system. Each digit position represents a power of 16. As
the base is greater than 10, the number system is supplemented by letters.
Following are the hexadecimal symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 as A, 11
as B, 12 as C, 13 as D, 14 as E and 15 as F
To take A, B, C, D, E, and F as part of the number system is conventional and
has no logical or deductive reason.
NUMBER CONVERSIONS
Conversion of decimal number to any number system require following steps:
Step 1: convert the integer part by doing successive division using the radix of asked
number systems.
Step 2: convert the fractional part by doing successive multiplication using radix of
asked number system
Decimal-to-Binary Conversion
Integer Part
Radix/Base Number ÷ Base Remainder
2 25 1
2 12 0
2 6 0
2 3 1
2 1
Decimal Part
Decimal Part x Base Result Value
0.15625 x 2 0.31250 0
0.31250 x 2 0.62500 0
0.62500 x 2 1.25000 1
0.25000 x 2 0.50000 0
0.50000 x 2 1.00000 1
Decimal-to-Octal Conversion
Integer Part
Radix/Base Number ÷ Base Remainder
8 89 1
8 11 3
1
Decimal Part
Decimal Part x Base Result Value
0.1625 x 8 1.3000 1
0.3000 x 8 2.4000 2
0.4000 x 8 3.2000 3
0.2000 x 8 1.6000 1
0.6000 x 8 4.8000 4
0.8000 x 8 6.4000 6
Since fractional part is repeating so stop
Decimal-to-Hexadecimal Conversion
Integer Part
Radix/Base Number ÷ Base Remainder
16 778 10 A
16 48 0
3
Decimal Part
Decimal Part x Base Result Value
0.7625 x 16 12.2000 12 C
0.2000 x 16 3.2000 3
0.2000 x 16 3.2000 3
Since fractional part is repeating so stop
Binary-to-Decimal Conversion
Any binary number can be converted into decimal number using the weights assigned
to each bit as per its base.
(MSB) (LSB)
Bits 1 1 0 1 1
Weights 24 23 22 21 20 Bit x Weight
1 x 20 = 1
1 x 21 = 2
0 x 22 = 0
1 x 23 = 8
1 x 24 = 16
Sum = 27
Hence, (11011)2 = (27)10
Integer Part
Bits 1 0 1 0 1
Weights 24 23 22 21 20 Bit x Weight
1 x 20 = 1
0 x 21 = 0
1 x 22 = 4
0 x 23 = 0
1 x 24 = 16
Sum = 21
Integer Part (10101)2 = (21)10
Decimal Part :
Bits 1 1 0 1
Weights 2-1 2-2 2-3 2-4
Bit x Weight Value
1 x 2-4 = 1 x 1/24 =0.0625
0 x 2-3 = 0 x 1/23 =0
1 x 2-2 = 1 x 1/22 =0.25
1 x 2-1 = 1 x 1/21=0.50
Sum = 0.8125
So, (1101)2 = (0.8125)10
Octal-to-Decimal Conversion
Bits 7 3 5
Weights 82 81 80
Bit x Weight
5 x 80 = 5
3 x 81 = 24
7 x 82 = 448
Sum = 477
Hence, (735)8 = (477)10
Integer Part
Bits 1 4 6
Weights 82 81 80
Bit x Weight
6 x 80 = 6
4 x 81 = 32
1 x 82 = 64
Sum = 102
Integer Part (146)8 = (102)10
Decimal Part :
Bits 5 1
Weights 8-1 8-2
Bit x Weight Value
1 x 8-2 = 1 x 1/82= 1/64
5 x 8-1 = 0 x 1/8 = 5/8
Sum = 0.640625
So, (51)2 = (0.640625)10
Hexadecimal-to-Decimal Conversion
Bits 2 A 5 B
Weights 163 162 161 160
Bit x Weight
11 x 160 = 11
5 x 161 = 80
10 x 162 = 2560
2 x 163 = 8192
Sum = 10843
Hence, (2A5B)16 = (10843)10
Integer Part:
Bits 2 D
Weights 161 160
Bit x Weight
13 x 160 = 13
2 x 161 = 32
Sum = 45
so, (2D)16 = (45)10
Decimal Part:
Bits 5 B
Weights 16-1 16-2
Bit x Weight
11 x 16-2 = 11/256 = 0.04296875
5 x 161 = 5/16 = 0.3125
Sum = 0.35546875
So, (0.5B)16 = (0.35546875)10
Octal-to-Binary Conversion
It is carried out using an octal number table which is having a three-bit equivalent binary
number for each octal digit. Here the given octal number is converted into equivalent
3-bit binary number using this table.
Octal Number 4 0 7
3-Bit Binary Number 100 000 111
Octal Number 7 0 0 . 0 3 5 6
3-Bit Binary Number 111 000 000 . 000 011 101 110
Binary-to-Octal Conversion
It is also carried out using an octal number table having a three-bit equivalent binary
number for each octal digit. For every given binary number, we make a group of three
bits from right to left for integer part and from left to right for the fractional part starting
from the decimal point. If the left most group in the integer part and the right most
group in the fractional part represent with less than 3-bits then we make that group
complete by adding one or two zeros.
Hexadecimal-to-Binary Conversion
It is carried out using a hexadecimal number table which is having a four-bit equivalent
binary number for each hexadecimal digits. Here the given hexadecimal number is
converted into equivalent 4-bit binary number using this table.
Hexadecimal Number 2 9 A 6
4-Bit Binary Number 0010 1001 1010 0110
Hexadecimal Number D C 5 A . 3 E 4
4-Bit Binary Number 1101 1100 0101 1010 . 0011 1110 0100
Binary-to-Hexadecimal Conversion
It is also carried out using a hexadecimal number table having a 4-bit equivalent binary
number for each hexadecimal digit. For every given binary number, we make a group
of 4-bits from right to left for integer part and from left to right for the fractional part
starting from the decimal point. If the left most group in the integer part and the right
most group in the fractional part represent with less than 4-bits then we make that group
complete by adding one, two or three zeros.
Hexadecimal-to-Octal
Hexadecimal Number 2 7 A 9
4-Bit Binary Number 0010 0111 1010 1001
Hexadecimal Number 8 5 C . B D 3
4-Bit Binary Number 1000 0101 1100 . 1011 1100 0011
(L←R) (L→R)
3-Bit Binary Number 100 001 011 100 . 101 111 010 011
Octal Number 4 1 3 4 . 5 7 2 3
Octal-to-Hexadecimal Conversion
For converting Octal Number to Hexadecimal Number, we first have to convert given
Octal Number into Binary Number using 3-bit code and then convert this Binary
Number into Hexadecimal Number using 4-bit code.
Octal Number 3 5 6 2
3-Bit Binary Number 011 101 110 010
Octal Number 4 5 6 7 . 2 6 6
3-Bit Binary Number 100 101 110 111 . 010 110 110
(1) Sign-Magnitude
(2) 1’s Complement
(3) 2’s Complement
Sign-Magnitude Form
The binary number in sign-magnitude form is represented by one sign bit and
magnitude bits. The MSB (Left Most Bit) in the signed number is the sign bit which is set to
‘0’ indicating a positive number and ‘1’ indicating a negative number. The magnitude bits gives
the value of the signed number.
Example :
(110110)2 represents (-22)10. The MSB is ‘1’ which indicates that the number is
negative and the remaining 5-bits gives its magnitude.
1 1 0 1 1 0
Sign-Bit
Magnitude Bits
Similarly, (010110)2 represents (+22)10. The MSB is ‘0’ which indicates that the
number is positive and the remaining 5-bits gives its magnitude.
0 1 0 1 1 0
Sign-Bit
Magnitude Bits
One’s / 1’s Complement of any binary number can be obtained by changing all 1’s with
0’s and all 0’s with 1’s. This form is used for representing the signed numbers.
In 1’s complement form, if the number is Positive, then the 1’s complement of that
number is negative with the same value (magnitude)
Example:
With 4-bits
Maximum Positive number is (24-1 – 1) = (8 – 1) = (+7)10
Maximum Negative number is - (24-1 – 1) = - (8 – 1) = (-7)10
With 5-bits
Maximum Positive number is (25-1 – 1) = (16 – 1) = (+15)10
Maximum Negative number is - (25-1 – 1) = - (16 – 1) = (-15)10
Two’s / 2’s Complement of any binary number can be obtained by adding 1 to 1’s
complement of the binary number. Signed numbers are represented similar to 1’s
complement form in 2’s complement form. It is most widely used in Computer (ALU) to
represent negative numbers.
If a binary number is positive, then 2’s complement of that number is negative with the
same value.
Example:
With 4-bits
Maximum Positive number is (24-1 – 1) = (8 – 1) = (+7)10
Maximum Negative number is - ( 24-1 ) = - (8) = (-8)10
With 5-bits
Maximum Positive number is (25-1 – 1) = (16 – 1) = (+15)10
Maximum Negative number is - (25-1) = - (16) = (-16)10
Binary operation is an operation that requires two inputs. These inputs are known as operands.
The binary operation of addition, multiplication, subtraction and division takes place on two
operands. Even when we add any three binary numbers, we first add two numbers and then the
third number will be added to the result of the two numbers. Thus, the mathematical operations
which are done with the two numbers are known as binary operations.
Binary Addition
The result obtained after adding two binary numbers is the binary number itself. Binary
addition is the simplest method to add any of the binary numbers.
Rules
• 0+0=0
• 0+1=1
• 1+0=1
• 1 + 1 =10 (Sum = 0, Carry = 1)
Binary Subtraction
The result obtained after subtracting two binary numbers is the binary number itself.
Binary subtraction is also the simplest method to subtract any of the binary numbers.
Rules
• 0–0=0
• 0 – 1 = 1 (with a borrow of 1)
• 1–0=1
• 1–1=0
1 0 10 1
- 0 1 1 0
0 0 1 1
Binary Multiplication
The binary multiplications are calculated similarly as the other arithmetic numerals are
calculated.
Rules
• 0×0=0
• 0×1=0
• 1×0=0
• 1×1=1
1 1 0 1
x 1 0 1 0
0 0 0 0
1 1 0 1
0 0 0 0
+ 1 1 0 1
1 0 0 0 0 0 1 0
Binary Division
The method of binary division is similar to the 10 decimal system other than the base 2
system.
Rules:
• 1÷1=1
• 0÷1=0
• 1 ÷ 0 = Not Defined
• 0 ÷ 0 = Not Defined
In the digital logic circuits, each decimal or piece of information is represented through
an equivalent combination of binary digits. A complete group of such combinations,
which represents numbers, layers, or symbols, is known as a digital or binary code.
Further, the method of converting a decimal number to a binary number is called
coding. These are codes, which apparently look like to be a combination of binary
numbers, however, they are not featured according to the ideology of binary numbers.
These codes are normally used in order to switch binary numbers from one system to
the other.
Codes are used for security purposes so that in case the message has been detected, it
may not be deciphered or decoded. In modern digital instruments, codes are used in
order to describe, represent and process arithmetic information (i.e. addition,
subtraction, multiplication, and division). The selection of a code depends on the nature
or purpose of the work going to be availed through it. Some codes are suitable for
conducting arithmetic processes while others are famous for their high accuracy and
efficiency (i.e. such codes deliver significant information through the application of a
few bits)
Under specific applications, the circuit required for processing of information becomes
simple and concise as a result of the application of one code or the other. Further, the
reliability of a digital system enhances as a result of a finite switching circuit.
Further codes being used in the digital systems are of the following two types
1. Numeric weighted code
2. Special binary codes or non-weighted code
These are the codes wherein every decimal digit is denoted by a group of four bits. As
the weight of a 4-bit position from right to left is 8-4-2-1, that’s why it is also known
as an 8421 code. As every digit present in it has a specific weight, that’s the reason it
is generally considered as a weighted or numerical code.
Binary Code Decimal (BCD) is a method for the description of every decimal digit
with respect to its binary code. As there are just 10 code groups (0-9) in the BCD
system, therefore it is quite easy to convert decimal to BCD or BCD to decimal. As a
result of being familiar with the decimal number system, we prefer to read or write in
decimals. Whereas, looking at any binary number, it seems a bit difficult to calculate
an equivalent decimal number forthwith.
Thus, this process entails a substantial waste of time, which is a significant drawback
of the binary to decimal conversion method (which has been discussed in the previous
pages). In order get rid of the specific flaw, engineers have designed a special code
which keenly resembles a decimal number system. This specific code is called BCD.
As decimal numbers are used on input and output of most of the digital components
and circuits, therefore this particular code is fairly popular owing to having a
characteristic combination of both binary as well as digital systems.
In other words, Binary Coded Decimal (or the decimal coded into binary) means
expression of every decimal digit (0-9) by means of a 4 – bits binary code, while code
8421 represents the binary weights of these four bits (i.e. 23, 22, 21, 20). The greatest
advantage of this code is that it is pretty easy to interconvert 8421 code numbers with
ordinary decimal numbers. Remember that a total of 16 binary numbers (from 0000 to
1111) can be represented with 4 – bits. However, only first ten numbers out of these are
used in 8421 code, whereas the remaining six (i.e. 1010, 1011, 1100, 1101, 1110 and
1111) have been invalidated in the BCD code 8421.
Decimal BCD
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
BCD codes are not simply analogous to the binary codes or Digital Codes.
For the purpose of converting any decimal number to BCD, a 4-digit binary code is
mentioned with its corresponding decimal digit. An appropriate space is also kept
within every 4 – bits group, so that a distinction could be maintained between an
ordinary binary code and a BCD code.
The greatest advantage of a BCD code is that it is fairly easy to read, write, identify and
even to memorize the arrangement of first 10 numbers. As BCD numbers look like
decimal numbers, therefore when we have to work continuously with BCD numbers,
we can quite easily convert a BCD number to an equivalent decimal number and a
decimal number into BCD instantly after having a look at these. However, in spite of
its merits, BCD code has certain deficiencies or drawbacks as well. For example,
performance of a BCD is inferior as compared to a pure binary code. Moreover,
relatively large bits are required for the conversion of any decimal number into a BCD
code. As a result, performance suffers, apart from the need for the provision of an extra
circuit (e.g. 25 in the pure binary code is written as 11001 (look at the table 1.2).
However, in situation of BCD, 25 is written as 0010 0101). Resultantly, cost goes up,
circuit becomes more complex and more power consuming. Moreover, by invalidating
or not using the six numbers (10 – 15) is in itself a major drawback. As a consequence,
effectiveness deteriorates further.
With the help of above table, replace the value of each decimal digit by its 4 – bit
equivalent from the BCD code.
3 = 0011, 6 = 0110, and 9 = 1001
Thus, (369)10 = 0011 0110 1001 in BCD
Starting from the LSB, the given number can be divided into groups of four bits as.
0001 0100 0111 0101
Gray Code
Gray code is a non – weighted or un – weighted and non – arithmetic code, which is
profusely employed in mechanical switching systems. It means that no specific weight
or position value is fixed for the bit positions of this code, nor can they be utilized for
any kind of arithmetic operations (i.e. gray code is not used when numbers are required
to be added, subtracted or during any other arithmetic operation). This code is also
known as a cyclic or reflective code.
Just like a pure binary code, the first ten digits (0 – 9) are also used in BCD. An
important advantage of gray code is that a change of only one bit takes place from one
code number to other (which has been explained via the table). The very advantage of
this code makes it pretty suitable for a number of applications.
For example, in a shaft position encoder, where the possibility of errors mounts owing
to a change between the quantity of bits of arranged numbers located adjacently. In
such situations, gray codes are enormously used, which eliminate inherent faults
existing in the binary code, because, a change of just one – bit occurs between such
end-to-end numbers. As a consequence, the quantity of switching declines and trust on
the switching system grows further. Moreover, function of the circuit also improves
effectively due to a minimum possibility of committing any sort of errors under the
gray code technique.
In table 1.7, a 4 – bit gray code has been displayed, which consists of a list of 4 – bit
gray codes for the decimal numbers ranged from 0 – 15. In order to comprehend
mechanism that a variation of just one bit occurs between one number of a gray code
to the other (or end -to – end numbers), it is necessary to go through the given table
carefully. For example, note down the change taking place between decimal number 3
and decimal number 4. As a result of an inter -change taking place between these two
decimal numbers, a change of just one bit occurs in the gray code from 0010 to 0110.
Whereas, in case of binary codes or Digital Codes, a change of 3 bits occurs from 0011
to 0100 (that’s 1st both bits change from 11 to 00 and the third bit changes from 0 to 1)
Excess-3 Code
Decimal BCD Excess-3
0 0000 0001
1 0001 0100
2 0010 0101
3 0011 0110
4 0100 0111
5 0101 1000
6 0110 1001
7 0111 1010
8 1000 1011
9 1001 1100
So, 0100 0101 is the excess -3 code which stands for decimal 12.
The special type of codes that are generally used to depict numbers, letters,
symbols, and instructions, are known as alpha–numeric codes (that’s the binary
codes or Digital Codes which are used in order to express the characteristics of
both alphabetic as well as alphanumeric type. Because for the transmission or
communication of information from one place to another, we not only need
numbers, we also require the application of certain letters)
ASCII consists a total of 128 characters and symbols, which is represented via
a binary code (i.e. it is a 7 – bit binary code because a total of 27= 128 different
conditions or numbers can be represented via a 7- bit). The first 32 ASCII
characters include non- graphic commands, which can neither be printed nor
displayed. Rather, these are only used for the purpose of exercising control.
Null, line feed, start of text and escape etc. are some of the instances of control
character. Other characters are graphic symbols, which can both be printed or
displayed. It contains letters of alphabet (i.e. capital and small English
characters), 10 decimal digits (i.e. numbers from 0 to 9) and punctuation signs
and other commonly used symbols and codes.
ASCII code comprises 128 characters and symbols. It represents every character
and symbol in a decimal, hexadecimal and binary. The names of 32 control
characters (00 to IF hexadecimal), have been presented in the left section. These
control characters are used for communication purposes while transmitting data
or information through devices e.g. computers and printers. Whereas graphic
symbols (from 20 to 7F hexadecimal) have been demonstrated in the remaining
section of the table.
In order to provide and receive information via a computer, we often need to apply
certain alpha numeric codes. There was a time when manufactures used their own alpha
– numeric codes, which caused all sorts of mix-up and confusion. Eventually, the
industry agreed on an input – output code, which is known as American Standard Code
for Information Interchange (ASCII). It must be remembered that ASCII is pronounced
as ask – ee). After the introduction of this code, different computer hardware’s e.g.
keyboard, printers, video displays etc. got standardized. ASCII is a 7 – bit code, the
format of which is as follows:
It should be remembered that the ASCII 7 – bit code for every letter, number or control
function is composed through a group of 3 – bit and another group of 4 – bit and that
the value of each X in every group is zero or 1. In the table 1.11, ASCII code has been
displayed. Through the application of this table, alphabet letters or some commonly
used symbols can be determined from top or bottom. For example, the table reveals that
the X4, X5, X6 value of capital letter A is 100 (this is binary value of 3 – bit) and value
of X0, X1, X2, X3 (i.e. binary value of next 4 – bit) is 0001. As such, the ASCII code
value for A is as under:
X6 X5 X4 X3 X2 X1 X0
1 0 0 0 0 0 1
ASCII code is quite extensively used in computers and data communication devices
(e.g. printers, telephone lines etc.) for data communication.
ASCII Code
X6X5X4
X3X2X1X0 010 011 100 101 110 111
0000 SP 0 @ P p
0001 ! 1 A Q a q
0010 “ 2 B R b r
0011 # 3 C S c s
0100 $ 4 D T d t
0101 % 5 E U e u
0110 & 6 F V f v
0111 ‘ 7 G W g w
1000 ( 8 H X h x
1001 ) 9 I Y i y
1010 * : J Z j z
1011 + ; K k
1100 ‘ < L l
1101 – = M m
1110 . > N n
1111 / ? O o
The data represented in ASCII format can be easily converted into EBCDIC format and
vice-versa, in-order to suit the requirements of a particular computer systems. Each
EBCDIC character is represented by a unique string of 1’s and 0’s, with each string of
8-bits. The 4 Left-handed bits are referred to as “Zone Bits”, which identify the group
classification of a character. The 4 Right-handed bits are referred to as “Numeric Bits”
representing code.
We know that the bits 0 and 1 corresponding to two different range of analog voltages.
So, during transmission of binary data from one system to the other, the noise may also
be added. Due to this, there may be errors in the received data at other system. That
means a bit 0 may change to 1 or a bit 1 may change to 0. We can’t avoid the
interference of noise. But, we can get back the original data first by detecting whether
any errors present and then correcting those errors. For this purpose, we can use the
following codes.
• Error detection codes
• Error correction codes
They are used to correct the errors present in the received data bitstream so that, we will
get the original data. Error correction codes also use the similar strategy of error
detection codes.
Example − Hamming code.
Therefore, to detect and correct the errors, additional bits are appended to the data bits at the
time of transmission.
Parity Code
It is easy to include append one parity bit either to the left of MSB or to the right of
LSB of original bit stream. There are two types of parity codes, namely Even Parity
code and Odd Parity code based on the type of parity being chosen.
000 0 0000
001 1 0011
010 1 0101
011 0 0110
100 1 1001
101 0 1010
110 0 1100
111 1 1111
Here, the number of bits present in the even parity codes is 4. So, the possible
even number of ones in these even parity codes are 0, 2 & 4.
• If the other system receives one of these even parity codes, then there is
no error in the received data. The bits other than even parity bit are same
as that of binary code.
• If the other system receives other than even parity codes, then there will
be an errors in the received data. In this case, we can’t predict the
original binary code because we don’t know the bit positions of error.
Therefore, even parity bit is useful only for detection of error in the received
parity code. But, it is not sufficient to correct the error.
000 1 0001
001 0 0010
010 0 0100
011 1 0111
100 0 1000
101 1 1011
110 1 1101
111 0 1110
Here, the number of bits present in the odd parity codes is 4. So, the possible
odd number of ones in these odd parity codes are 1 & 3.
• If the other system receives one of these odd parity codes, then there is
no error in the received data. The bits other than odd parity bit are same
as that of binary code.
• If the other system receives other than odd parity codes, then there is an
errors in the received data. In this case, we can’t predict the original
binary code because we don’t know the bit positions of error.
Therefore, odd parity bit is useful only for detection of error in the received
parity code. But, it is not sufficient to correct the error.
Hamming Code
Hamming code is useful for both detection and correction of error present in the
received data. This code uses multiple parity bits and we have to place these parity bits
in the positions of powers of 2.
The minimum value of 'k' for which the following relation is correct valid is nothing
but the required number of parity bits.
2k≥n+k+1
Where,
‘n’ is the number of bits in the binary code information
‘k’ is the number of parity bits
Therefore, the number of bits in the Hamming code is equal to n + k.
Based on requirement, we can use either even parity or odd parity while forming a
Hamming code. But, the same parity technique should be used in order to find whether
any error present in the received data.
• Find the value of p2, based on the number of ones present in bit positions b3, b6,
b7 and so on. All these bit positions suffixes in their equivalent binary have ‘1’
in the place value of 21.
• Find the value of p3, based on the number of ones present in bit positions b5, b6,
b7 and so on. All these bit positions suffixes in their equivalent binary have ‘1’
in the place value of 22.
• Find the value of c2, based on the number of ones present in bit positions b2, b3,
b6, b7 and so on. All these bit positions suffixes in their equivalent binary have
‘1’ in the place value of 21.
• Find the value of c3, based on the number of ones present in bit positions b4, b5,
b6, b7 and so on. All these bit positions suffixes in their equivalent binary have
‘1’ in the place value of 22.
The decimal equivalent of the check bits in the received data gives the value of bit
position, where the error is present. Just complement the value present in that bit
position. Therefore, we will get the original binary code after removing parity bits.
Example: find the Hamming code for binary code, d4d3d2d1 = 1000. Consider even
parity bits.
We can find the required number of parity bits by using the following mathematical
relation: 2k ≥ n+k+1
The minimum value of k that satisfied the above relation is 3. Hence, we require 3 parity
bits p1, p2, and p3. Therefore, the number of bits in Hamming code will be 7, since there
are 4 bits in binary code and 3 parity bits. We have to place the parity bits and bits of
binary code in the Hamming code as shown below.
p1 = b7 ⊕ b5 ⊕ b3 = 1 ⊕ 0 ⊕ 0 = 1
p2 = b7 ⊕ b6 ⊕ b3 = 1 ⊕ 0 ⊕ 0 = 1
p3 = b7 ⊕ b6 ⊕ b5 = 1 ⊕ 0 ⊕ 0 = 1
By substituting these parity bits, the Hamming code will be b7b6b5b4b3b2b1 = 1001011
The decimal value of check bits gives the position of error in received Hamming code.
c3c2c1 = (011)2 = (3)10
Therefore, the error present in third bit (b3) of Hamming code. Just complement the
value present in that bit and remove parity bits in order to get the original binary code.
REFERENCES
(1) https://www.javatpoint.com
(2) https://www.tutorialspoint.com
(3) https://www.geeksforgeeks.org
inprotected.com