DLD Module 1
DLD Module 1
Module 1
Human Beings communicate with each other in a particular language made of letters or
words. Those letters or words are normally typed through keyboard of the computer, but computer
does not understand the words and letters. Rather, those words and letters are translated into
numbers. This means that computers understand only numbers. We know the decimal (base
10) system, and are very comfortable with performing operations using this system, it is also
important for us to understand that the decimal system is not the only system in the world. By
studying other number systems such as binary (base 2), quaternary (base 4), octal (base 8),
hexadecimal (base 16) and so forth, we will gain a better understanding of how number systems
work in general. Number systems are the technique to represent numbers in the computer system
architecture, every value that you are saving or getting into/from computer memory has a defined
number system. As Computer architecture supports following number systems so we need to study
them and also need to know the conversion technique between them.
1.2 Motivation:
A digital circuit is one that is built with devices with two well-defined states. Such circuits can
process information represented in binary form. Systems based on digital circuits touch all aspects
our present day lives. The present day home products including electronic games and appliances,
communication and office automation products, computers with a wide range of capabilities, and
industrial instrumentation and control systems, electro medical equipment, and defense and
aerospace systems are heavily dependent on digital circuits. Many fields that emerged later to digital
electronics have peaked and leveled off, but the application of digital concepts appears to be still
growing exponentially. This unprecedented growth is powered by the semiconductor technology,
which enables the introduction of more and has been doubling every eighteen months (Moore’ Law)
for several decades and reached the figure of almost one billion transistors per chip. This allowed
the circuit designers to provide more and more complex functions in a single unit.
At the end of this chapter, students will be able to understand number systems and codes, Boolean
algebra and basic and universal gates.
1.3 Scope:
The number systems are widely used in computers which, in turn, always demands unambiguous
definition of the problem, which is simple to carry out and straight forward to implement in order to
solve the problem. Computers are also involved in generating codes which are widely used for
reliable and secure communication in areas such as communication, computation and in sectors like
banking etc.
1.4 Syllabus:
1.7 LearningObjectives:
Students will gain information on analog and digital signals, their comparison, various number
systems used and codes. Number system is explained in detail with examples.
N= Symbols
r= radix of the system
LSB= Least Significant Bit
MSB= Most Significant Bit
Analog System: A system can be defined as a physical device that performs an operation on a
signal. Analog devices and systems process signals whose voltages or other quantities vary in a
continuous manner. They can take on any value across a continuous range of voltage, current, or
other metric.
Digital System: A digital system is the one that handles only discrete values or signals.
Analog Signal: An analog signal is the one whose voltage or other quantities vary in continuous
manner. The analog signals can have an infinite number of values. They have a value that changes
steadily over time and can have any one of an infinite set of values in a range.
Digital Signal: Digital signals are non-continuous, they change in individual steps. They consist of
pulses or digits with discrete levels or values. Digital signals have two amplitude levels. The value of
which are specified as one of two possibilities such as 1 or 0, HIGH or LOW , TRUE or FALSE and so
on. In reality, the values are anywhere within specific ranges and we define values within a given
range.
Logic Expression: A mathematical formula consisting of logical operators and variables.
Logic Operator: A function that gives a well-defined output according to switching algebra.
Logic Variable: A symbol representing the two possible switching algebra values of 0 and 1.
Logic Literal: The values 0 and 1 or a logic variable or its complement.
Module 1: Number Systems and Codes 3
Learning Objective: Students will learn about the advantages of Digital signals over Analog
Signals. They will also learn in short about the various number systems
1.11 Introduction
Signals carry information and are defined as any physical quantity that varies with time, space,
or any other independent variable. For example, a sine wave whose amplitude varies with
respect to time or the motion of a particle with respect to space can be considered as signals. A
system can be defined as a physical device that performs an operation on a signal. For example,
an amplifier is used to amplify the input signal amplitude. In this case, the amplifier performs
some operation(s) on the signal, which has the effect of increasing the amplitude of the desired
information-bearing signal.
1.11.1 Digital and Analog Signals
Signals carry information and are defined as any physical quantity that varies with time, space,
or any other independent variable. For example, a sine wave whose amplitude varies with
respect to time or the motion of a particle with respect to space can be considered as signals. A
system can be defined as a physical device that performs an operation on a signal. For example,
an amplifier is used to amplify the input signal amplitude. In this case, the amplifier performs
some operation(s) on the signal, which has the effect of increasing the amplitude of the desired
information-bearing signal.
Signals can be categorized in various ways; for example discrete and continuous time domains.
Discrete-time signals are defined only on a discrete set of times. Continuous-time signals are
often referred to as continuous signals even when the signal functions are not continuous; an
example is a square-wave signal.
Another category of signals is discrete-valued and continuous-valued or otherwise known as
digital and analog signals. Analog devices and systems process signals whose voltages or other
quantities vary in a continuous manner. They can take on any value across a continuous range
of voltage, current, or other metric. The analog signals can have an infinite number of values.
Analog systems can be called wave systems. They have a value that changes steadily over time
and can have any one of an infinite set of values in a range.
For example, the telephone transmitter converts the sounds into an electrical voltage signal.
The intensity of the voice causes electric current variations. Therefore, the two are analogous
hence the name analog. At the receiving end, the signal is reproduced in the same proportion.
Hence the electric current is a model and is an electrical representation of one's voice.
Digital signals are non-continuous, they change in individual steps. They consist of pulses or
digits with discrete levels or values. The value of each pulse is constant, but there is an abrupt
change from one digit to the next.
A digital system is the one that handles only discrete values or signals. Any set that is restricted
to a finite number of elements contains discrete information. The word digital describes any
system based on discontinuous data or events. Digital is the method of storing, processing and
transmitting information through the use of distinct electronic pulses that represent the binary
digits 0 and 1. Examples of discrete sets are the 10 decimal digits, the 26 letters of the alphabet
etc. A digital system would be to flick the light switch on and off. There's no 'in between' values.
The usual advantages of digital circuits when compared to analog circuits are:
1. Noise Margin (resistance to noise/robustness): Digital circuits are less affected by
noise. If the noise is below a certain level (the noise margin), a digital circuit behaves as if
there was no noise at all. The stream of bits can be reconstructed into a perfect replica of
the original source. However, if the noise exceeds this level, the digital circuit cannot give
Module 1: Number Systems and Codes 4
correct results.
2. Error Correction and Detection: Digital signals can be regenerated to achieve lossless
data transmission, within certain limits. Analog signal transmission and processing, by
contrast, always introduces noise.
3. Easily Programmable: Digital systems interface well with computers and are easy to
control with software. It is often possible to add new features to a digital system without
changing hardware, and to do this remotely, just by uploading new software. Design
errors or bugs can be worked-around with a software upgrade, after the product is in
customer hands. A digital system is often preferred because of (re-)programmability and
ease of upgrading without requiring hardware changes.
4. Cheap Electronic Circuits: More digital circuitry can be fabricated per square
millimeter of integrated-circuit material. Information storage can be much easier in
digital systems than in analog ones. In particular, the great noise-immunity of digital
systems makes it possible to store data and retrieve it later without degradation. In an
analog system, aging and wear and tear will degrade the information in storage, but in a
digital system, as long as the wear and tear is below a certain level, the information can be
recovered perfectly. Theoretically, there is no data-loss when copying digital data. This is a
great advantage over analog systems, which faithfully reproduce every bit of noise that
makes its way into the signal.
1.11.3 Disadvantages
1. The world in which we live is analog, and signals from this world such as light,
temperature, sound, electrical conductivity, electric and magnetic fields, and phenomena
such as the flow of time, are for most practical purposes continuous and thus analog
quantities rather than discrete digital ones. For a digital system to do useful things in the
real world, translation from the continuous realm to the discrete digital realm must occur,
resulting in quantization errors. This problem can usually be mitigated by designing the
system to store enough digital data to represent the signal to the desired degree of fidelity.
The Nyquist-Shannon sampling theorem provides an important guideline as to how much
digital data is needed to accurately portray a given analog signal.
2. Digital systems can be fragile, in that if a single piece of digital data is lost or
misinterpreted, the meaning of large blocks of related data can completely change. This
problem can be diminished by designing the digital system for robustness.
3. Digital circuits use more energy than analog circuits to accomplish the same calculations
and signal processing tasks, thus producing more heat as well. In portable or battery-
powered systems this can be a major limiting factor.
4. Digital circuits are made from analog components, and care has to be taken to all noise
and timing margins, to parasitic inductances and capacitances, to proper filtering of
power and ground connections, to electromagnetic coupling amongst data lines.
Inattention to these can cause problems such as "glitches", pulses do not reach valid
switching (threshold) voltages, or unexpected ("undecoded") combinations of logic states.
Number systems are the base for all kind of operation. It plays an important role, a role
which links the machine world to the reality which one can see as a key to all kind of
operation which is being performed in our daily activity.
Different kinds of Number System go as Decimal Number which one is studying from
childhood, second term one would have come across is Binary Number Systems. We also
come across new terminology now such as Octal Number and Hexadecimal Numbers
Number systems provide the basis for all operations in information processing systems. In a
number system the information is divided into a group of symbols; for example, 26 English
letters, 10 decimal digits etc. In conventional arithmetic, a number system based upon ten
units (0 to 9) is used. However, arithmetic and logic circuits used in computers and other
digital systems operate with only 0's and 1's because it is very difficult to design circuits that
require ten distinct states. The number system with the basic symbols 0 and 1 is called binary
i.e. a binary system uses just two discrete values. The binary digit (either 0 or 1) is called a
bit.
A group of bits which is used to represent the discrete elements of information is a symbol.
The mapping of symbols to a binary value is known a binary code. This mapping must be
unique. For example, the decimal digits 0 through 9 are represented in a digital system with
a code of four bits. Thus a digital system is a system that manipulates discrete elements of
information that is represented internally in binary form.
There are four different number systems that we will study
A Binary number system has only two digits that are 0 and 1. Every number (value) represents with
0 and 1 in this number system. The base of binary number system is 2, because it has only two digits.
Applications:
Binary is found in computer technology. All computer language and programming is based on the 2-
digit number system used in digital encoding (is the process of taking data and representing it with
discreet bits of information).
The most common application for the binary number system can be found in computer technology.
All computer language and programming is based on the 2-digit number system used in digital
encoding. Digital encoding is the process of taking data and representing it with discreet bits of
information. These discreet bits consist of the 0s and 1s of the binary system.
Octal number system has only eight (8) digits from 0 to 7. Every number (value) represents with
0,1,2,3,4,5,6 and 7 in this number system. The base of octal number system is 8, because it has only
8 digits.
Applications:
Octal used to be used widely within IT basically how hexadecimal is used today. It was used as an
ideal abbreviation of binary because the bit size (amount of bits that could be handled at one go) of
the CPUs that were used at the time that being 26 and 36 bit. After CPUs converted to bit sizes of 32
and 64 bit octal was no longer utilized because, though both are still dividable by 8 they can also be
divided by 16 which is far more efficient. There are some places however where octal is still widely
utilized including within file permissions within UNIX (the source code for Linux, Mac os and
android along with other operating systems) to avoid having to add support for symbols for
hexadecimal. It is also used within digital displays that also have no support for symbols.
Octal was used widely in the Electronics and Computer Industry, as although digital electronics is
based on gates with only two states and is therefore fundamentally binary, binary numbers can
Module 1: Number Systems and Codes 6
quickly become long and hard to transcribe without errors. Their octal equivalents are much shorter
and easier to remember, and have a straight-forward way of conversion to/from binary.
The PDP-11 computer made by the Digital Equipment Corporation used the octal numeric system
exclusively for displaying memory addresses and content.
UNIX file system permissions have three sets (user, group, others) of three bit permissions (read,
write, execute), which is naturally represented in octal.
The use of octal numbers has declined as most modern computers no longer base their word length
on multiples of three bits, (they are based on multiples of four bits, so hexadecimal is more widely
used).
Decimal number system has only ten (10) digits from 0 to 9. Every number (value) represents with
0,1,2,3,4,5,6, 7, 8 and 9 in this number system. The base of decimal number system is 10, because it
has only 10 digits.
Applications:
We use decimals every day, while dealing with money, weight, length etc. Decimal numbers are used
in situations where more precision is required, than the whole numbers can provide. For example,
when we calculate our weight on the weighing machine, we do not always find the weight equal to a
whole number on the scale. In order to know our exact weight we must understand what the decimal
value on the scale means. This section deals with the concept of decimals in three important fields of
our daily life.
A Hexadecimal number system has sixteen (16) alphanumeric values from 0 to 9 and A to F. Every
number (value) represents with 0,1,2,3,4,5,6, 7, 8, 9, A, B, C, D, E and F in this number system. The
base of hexadecimal number system is 16, because it has 16 alphanumeric values. Here A is 10, B is
11, C is 12, D is 13, E is 14 and F is 15.
Applications:
A computer understands information composed of only Zeros and Ones. Therefore, when we type
some letters or words, data is processed by the computer in the form of 0s and 1s. A computer can
understand positional number system where there are only a few symbols called digits and these
symbols represent different values depending on the position they occupy in the number. Computer
is usually designed to process hexadecimal number.
For example, the images you see on your computer screen have been encoded with a binary line for
each pixel. If a screen is using a 16-bit code, then each pixel has been told what color to display
based on which bits are 0s and which bits are 1s. As a result, 2^16 represents 65,536 different colors!
We also find the binary number system in a branch of mathematics known as Boolean algebra. This
field of mathematics is concerned with logic and truth values. Here, statements that are either true
or false are then assigned a 0 or 1.
Hexadecimal numbering system is often used by programmers to simplify the binary numbering
system. Since 16 is equivalent to 24, there is a linear relationship between the numbers 2 and 16.
This means that one hexadecimal digit is equivalent to four binary digits. Computers use binary
numbering system while humans use hexadecimal numbering system to shorten binary and make it
easier to understand.
• To define locations in memory. Hexadecimals can characterize every byte as two hexadecimal
digits only compared to eight digits when using binary.
• To define colors on web pages. Each primary color – red, green and blue is characterized by two
hexadecimal digits. The format being used is #RRGGBB. RR stands for red, GG stands for green
and BB stands for blue.
• To represent Media Access Control (MAC) addresses. MAC addresses consist of 12-digit
hexadecimal numbers. The format being used is either MM:MM:MM:SS: SS: SS or MMMM-
MMSS-SSSS. The first 6 digits of the MAC address represent the ID of the adapter manufacturer
while the last 6 digits represent the serial number of the adapter.
• To display error messages. Hexadecimals are used to define the memory location of the error.
This is useful for programmers in finding and fixing errors.
Learning from the topic: - Students will be able to explain difference between analog and digital
signals along with listing of advantages and disadvantages of digital systems. Also, they would be able
to identify various number systems and explain about decimal, octal, hexadecimal and binary number
system.
Learning Objective: Students will learn about various number systems and also how to
represent a negative number in various number systems . They will also learn how to find two’s
complement of a number.
I. Decimal Numbers
The invention of decimal number system has been the most important factor in the
development of science and technology. The decimal number system uses positional number
Module 1: Number Systems and Codes 8
representation, which means that the value of each digit is determined by its position in a
number.
The base, also called the radix of a number system is the number of symbols that the system
contains. The decimal system has ten symbols: 0,1,2,3,4,5,6,7,8,9. In other words, it has a
base of 10. Each position in the decimal system is 10 times more significant than the previous
position. The numeric value of a decimal number is determined by multiplying each digit of
the number by the value of the position in which the digit appears and then adding the
products. Thus the number 2734 is interpreted as
2 * 1000 + 7 * 100 + 3 * 10+ 4 * 1= 2000 + 700 + 30 + 4
Here 4 is the least significant digit (LSD) and 2 is the most significant digit (MSD).
The binary number has a radix of 2. As r = 2, only two digits are needed, and these are 0 and
1. Like the decimal system, binary is a positional system, except that each bit position
corresponds to a power of 2 instead of a power of 10. In digital systems, the binary number
system and other number systems closely related to it are used almost exclusively. Hence,
digital systems often provide conversion between decimal and binary numbers. The decimal
value of a binary number can be formed by multiplying each power of 2 by either 1 or 0
followed by adding the values together.
Example: The decimal equivalent of the binary number 101010.
N=101010
= 1 x 25 + 0 x 24 + 1 x 23 + 1 x 22 + 1 x 20
= 43
In binary r bits can represent symbols. e.g. 3 bits can represent up to 8 symbols, 4 bits
for 16 symbols etc. For N symbols to be represented, the minimum number of bits required is
the lowest integer 'r'' that satisfies the relationship. 2r>N
E.g. if N = 26, minimum r is 5 since 24=16 and 25 =32.
Digital systems operate only on binary numbers. Since binary numbers are often very long,
two shorthand notations, octal and hexadecimal, are used for representing large binary
numbers. Octal systems use a base or radix of 8. Thus it has digits from 0 to 7 (r-1). As in the
decimal and binary systems, the positional valued of each digit in a sequence of numbers is
fixed. Each position in an octal number is a power of 8, and each position is 8 times more
significant than the previous position.
Example: The decimal equivalent of the octal number 15.2.
N = 15.28
= 1 * 81 + 5 * 80 + 2*-1
=13.25
The hexadecimal numbering system has a base of 16. There are 16 symbols. The decimal
digits 0 to 9 are used as the first ten digits as in the decimal system, followed by the letters A,
B, C, D, E and F, which represent the values 10, 11,12,13,14 and 15 respectively. Table 1 shows
Module 1: Number Systems and Codes 9
the relationship between decimal, binary, octal and hexadecimal number systems.
Hexadecimal numbers are often used in describing the data in computer memory. A
computer memory stores a large number of words, each of which is a standard size collection
of bits. An 8-bit word is known as a Byte. A hexadecimal digit may be considered as half of a
byte. Two hexadecimal digits constitute one byte, the rightmost 4 bits corresponding to half a
byte, and the leftmost 4 bits corresponding to the other half of the byte. Often a half-byte is
called nibble.
The negative numbers are generally represented with sign magnitude i.e. reserve one bit for
the sign and the rest of bits are interpreted directly as the number. For example in a 4 bit
system, 0000 to 0111 can be used to positive numbers from +0 to +2n-1 and represent 1000
to 1111 can be used for negative numbers from -0 to -2n-1. The two possible zero's redundant
and also it can be seen that such representations are arithmetically costly. 2's complement
is a special case of complement representation. The negative number -k is equal to 2 n -k.
In 4 bits system, positive numbers 0 to 2n-1 is represented by 0000 to 0111 and negative
numbers -2n-1 to -1 is represented by 1000 to 1111. Such a representation has only one zero
and arithmetic is easier. To negate a number complement all bits and add 1.
Example:
119 10 = 01110111 2
10001000
+1 add 1
10001001
that is 10001001 2 = - 119 10
2. 101 + 101 is
a. 0101 b.202 c.1110 d. 1010
Ans: d
Learning Objective: Students will learn how to perform Binary Arithmetic operations and how
to convert a number from one system to another.
I. Binary Addition
0 0 0 1 0 0 1 1 = 19(base 10)
+0 0 1 1 1 1 1 0 = 62(base 10)
___________________________
0 1 0 1 0 0 0 1 = 81(base 10)
__________________________
2. 00001000 +00000011
Example:
Examples:
Example
Integer remainder
23
11 1 LSB
5 1
2 1
1 0
0 1 MSB
The answer is 23 10 = 10111 2
Divide number by 2; keep track of remainder; repeat with dividend equal to quotient until
zero; first remainder is binary LSB and last is MSB.
The conversion from decimal integers to any base-r system is similar to this above example,
except that division is done by r instead of 2.
Example:
Convert (0.7854) 10 to binary.
0.7854 x 2 = 1.5708; a -1 = 1
Module 1: Number Systems and Codes 14
0.5708 x 2 = 1.1416; a -2 = 1
0.1416 x 2 = 0.2832; a -3 = 0
0.2832 x 2 = 0.5664; a -4 = 0
The answer is (0.7854) 10 = (0.1100) 2
Multiply fraction by two; keep track of integer part; repeat with multiplier equal to product
fraction; first integer is MSB , last is the LSB; conversion may not be exact; a repeated
fraction. The conversion from decimal fraction to any base-r system is similar to this above
example, except the multiplication is done by r instead of 2.
The conversion of decimal numbers with both integer and fraction parts is done by
converting the integer and the fraction separately and then combining the two answers.
For converting a binary number to octal, the following two step procedure can be used.
1. Group the number of bits into 3's starting at least significant symbol. If the number of bits
is not evenly divisible by 3, then add 0's at the most significant end.
2. Write the corresponding 1 octal digit for each group
Examples:
100 010 111 (binary)
4 2 7 (octal)
2 5 6 (octal)
Similarly for converting a binary number to hex, the following two step procedure can be
used.
1. Group the number of bits into 4's starting at least significant symbol. If the number of bits
is not evenly divisible by 4, then add 0's at the most significant end.
2. Write the corresponding 1 hex digit for each group
Example:
1001 1110 0111 0000 (binary)
9 e 7 0 (hex)
1 1111 1010 0011 (binary)
1 f a 3 (hex)
The hex to binary conversion is very simple; just write down the 4 bit binary code for each
hexadecimal digit
Example:
3 9 c 8 (hex)
0011 1001 1100 1000 (binary)
Similarly for octal to binary conversion, write down the 8 bit binary code for each octal digit.
The hex to octal conversion can be carried out in 2 steps; first the hex to binary followed by
the binary to octal. Similarly, decimal to hex conversion is completed in 2 steps; first the
decimal to binary and from binary to hex as described above.
4. The maximum negative number that can be represented in 2’s complement form of n-bit
number is
a. -2n-1 b. -2n-1-1 c. -2n+1-1 d. -2n-1+1
Ans: a
5. The maximum positive number that can be represented in 2’s complement form of n-bit number
is
a. 2n-1-1 b. 2n-1+1 c. 2n-1 d. 2n+1
Ans : a
Module 1: Number Systems and Codes 16
Learning from the topic: - Students will be able to perform binary arithmetic operations and
converting a given number from one system to another.
Learning Objective: Students will learn detailed classification of Binary Codes and how to
convert from one code system to another. They will also learn about error detection and correction
by using parity bits.
1.11.8 Codes
Introduction
The first successful system of electrical communication was the telegraph, which was
invented by Samuel F.B. Morse in the year 1832. The telegraph operators used a code of
clicks to send the messages. If the key pressed for a short time it is the Morse code called ‘dot’
and if the key pressed for a long-time it is ‘Dash’. If it is observed logically, various
innumerable combinations of dots and dashes of any kind of words (even sentences) can be
written utilizing the above code. In the same way, binary digits also be utilized to make such
various innumerable combinations. These may be considered as Binary Codes.
Binary Codes
In the coding, when numbers, letters or words are represented by a specific group of
symbols, it is said that the number, letter or word is being encoded. The group of symbols is
called as a code. The digital data is represented, stored and transmitted as group of binary
bits. This group is also called as binary code. The binary code is represented by the number
as well as alphanumeric letter.
Module 1: Number Systems and Codes 17
Binary
codes
BCD or
2421 5211 Excess-3 Gray ASCII HOLLERITH EBCDIC Parity Hamming
8421
• Weighted Codes
• Non-Weighted Codes
• Alphanumeric Codes
• Error Detecting &Correcting Codes
A. Weighted Codes
Weighted binary codes are those binary codes which obey the positional weight principle.
Each position of the number represents a specific weight. Several systems of the codes are
used to express the decimal digits 0 through 9. In these codes each decimal digit is
represented by a group of four bits.
As the weights of this code are 8, 4, 2 and 1, therefore it is also called as 8421 code
Module 1: Number Systems and Codes 18
0 0000 0000
1 0001 0001
2 0010 0010
3 0011 0011
4 0100 0100
5 0101 0101
6 0110 0110
7 0111 0111
8 1000 1000
9 1001 1001
10 1010 0001 0000
11 1011 0001 0001
12 1100 0001 0010
13 1101 0001 0011
14 1110 0001 0100
15 1111 0001 0101
Table 1.2: Binary and BCD equivalent of Decimal numbers
Example
Let us find the BCD equivalent of the decimal number 786. This number has 3 decimal digits
7, 8 and 6. From the table, we can write the BCD 8421 codes of 7, 8 and 6 are 0111, 1000 and
0110 respectively.
∴ (786)10 = (011110000110)BCD
b. 2421 code
The weights of this code are 2, 4, 2 and 1.
0 0000 0000
1 0001 0001
2 0010 0010
3 0011 0011
4 0100 0100
5 0101 1011
6 0110 1100
7 0111 1101
8 1000 1110
Module 1: Number Systems and Codes 19
9 1001 1111
Table 1.3: Binary and 2421 code equivalent of Decimal numbers
Example
Let us find the 2421 equivalent of the decimal number 786. This number has 3 decimal
digits 7, 8 and 6. From the table, we can write the 2421 codes of 7, 8 and 6 are 1101, 1110 and
1100 respectively.
Therefore, the 2421 equivalent of the decimal number 786 is 110111101100.
c. 5211 Code
In this code, the bits carry binary weights 5, 2, 1, 1 from left to right.
0 0000 0000
1 0001 0001
2 0010 0011
3 0011 0101
4 0100 0111
5 0101 1000
6 0110 1010
7 0111 1100
8 1000 1110
9 1001 1111
B. Non-Weighted Codes
In this type of binary codes, the positional weights are not assigned. The examples of non-
weighted codes are Excess-3 code and Gray code.
a. Excess-3 code
The Excess-3 code is also called as XS-3 code. It is non-weighted code used to express
decimal numbers. The Excess-3 code words are derived from the 8421 BCD code words
adding (0011)2 or (3)10 to each code word in 8421. The excess-3 codes are obtained as
follows −
Example
6 0110 1001
7 0111 1010
8 1000 1011
9 1001 1100
b. Gray Code
It is the non-weighted code and it is not arithmetic codes. That means there are no specific
weights assigned to the bit position. It has a very special feature that, only one bit will change
each time the decimal number is incremented as shown in fig. As only one bit changes at a
time, the gray code is called as a unit distance code. The gray code is a cyclic code. Gray code
cannot be used for arithmetic operation.
Example
Let us convert 1010 from gray code to binary value:
Step 1: The MSB (Most Significant Bit) of a binary and gray code will be the same.
Module 1: Number Systems and Codes 21
Step 2: The next digit of binary will be the EXOR of the MSB of binary and the second
MSB of the gray code.
Step 3: Similarly EXOR the digit obtained in the previous step and the third MSB of gray
code to obtain the third MSB of binary.
Step 4: Repeat the previous step till the LSB of gray code is found.
Example
i. Let us take the binary number 01001 which we wish to convert to gray code. The steps to
perform this conversion are:
ii. The MSB is kept the same. As the MSB of the binary is 0, the MSB of the gray code will
be 0 as well (first gray bit)
iii. Next, take the XOR of the first and the second binary bit. The first bit is 0, and the
second bit is 1. The bits are different so the resultant gray bit will be 1 (second gray bit)
iv. Next, take the XOR of the second and third binary bit. The second bit is 1, and the third
bit is 0. These bits are again different so the resultant gray bit will be 1 (third gray bit)
v. Next, take the XOR of third and fourth binary bit. The third bit is 0, and the fourth bit is
0. As these are the same, the resultant gray bit will be 0 (fourth gray bit)
Module 1: Number Systems and Codes 22
vi. Lastly, take the XOR of the fourth and fifth binary bit. The fourth bit is 0, and the fifth
bit is 1. These bits are different so the resultant gray bit will be 1 (fifth gray bit)
vii. Hence the result of binary to gray code conversion of 01001 is complete, and the
equivalent gray code is 01101.
A binary digit or bit can represent only two symbols as it has only two states '0' or '1'. But this
is not enough for communication between two computers because there we need many more
symbols for communication. These symbols are required to represent 26 alphabets with
capital and small letters, numbers from 0 to 9, punctuation marks and other symbols.
The alphanumeric codes are the codes that represent numbers and alphabetic characters.
Mostly such codes also represent other characters such as symbol and various instructions
necessary for conveying information. An alphanumeric code should at least represent 10
digits and 26 letters of alphabet i.e. total 36 items. The following three alphanumeric codes
are very commonly used for the data representation.
• HollerithCode.
ASCII code is a 7-bit code whereas EBCDIC is an 8-bit code. ASCII code is more commonly
used worldwide while EBCDIC is used primarily in large IBM computers.
What is Error?
Error is a condition when the output information does not match with the input information.
During transmission, digital signals suffer from noise that can introduce errors in the binary
bits travelling from one system to other. That means a 0 bit may change to 1 or a 1 bit may
change to 0.
Module 1: Number Systems and Codes 23
Error-Detecting codes
Whenever a message is transmitted, it may get scrambled by noise or data may get
corrupted. To avoid this, we use error-detecting codes which are additional data added to a
given digital message to help us detect if an error occurred during transmission of the
message. A simple example of error-detecting code is parity check.
Error-Correcting codes
Along with error-detecting code, we can also pass some data to figure out the original
message from the corrupt message that we received. This type of code is called an error-
correcting code. Error-correcting codes also deploy the same strategy as error-detecting
codes but additionally, such codes also detect the exact location of the corrupt bit.
In error-correcting codes, parity check has a simple way to detect errors along with a
sophisticated mechanism to determine the corrupt bit location. Once the corrupt bit is
located, its value is reverted (from 0 to 1 or 1 to 0) to get the original message.
a. Parity Code
To detect and correct the errors, additional bits are added to the data bits at the time of
transmission. The additional bits are called parity bits. They allow detection or correction of
the errors. The data bits along with the parity bits form a code word.
It is the simplest technique for detecting and correcting errors. The MSB of an 8-bits word is
used as the parity bit and the remaining 7 bits are used as data or message bits. The parity of
8-bits transmitted word can be either even parity or odd parity.
Even parity -- Even parity means the number of 1's in the given word including the parity bit
should be even (2,4,6,....).
Odd parity -- Odd parity means the number of 1's in the given word including the parity bit
should be odd (1,3,5,....).
Module 1: Number Systems and Codes 24
The parity bit can be set to 0 and 1 depending on the type of the parity required.
• For even parity, this bit is set to 1 or 0 such that the no. of "1 bits" in the entire word is
even. Shown in fig. (a).
• For odd parity, this bit is set to 1 or 0 such that the no. of "1 bits" in the entire word is odd.
Shown in fig. (b).
Parity checking at the receiver can detect the presence of an error if the parity of the receiver
signal is different from the expected parity. That means, if it is known that the parity of the
transmitted signal is always going to be "even" and if the received signal has an odd parity,
then the receiver can conclude that the received signal is not correct. If an error is detected,
then the receiver will ignore the received byte and request for retransmission of the same
byte to the transmitter.
b. Hamming Code
Hamming code is a block code that is capable of detecting up to two simultaneous bit errors
and correcting single-bit errors. It was developed by R.W. Hamming for error correction.
In this coding method, the source encodes the message by inserting redundant bits within
the message. These redundant bits are extra bits that are generated and inserted at specific
positions in the message itself to enable error detection and correction. When the destination
receives this message, it performs recalculations to detect errors and find the bit position
that has error.
Module 1: Number Systems and Codes 25
Learning from the topic: - Students will be able to understand additional codes apart from
standard 4 types learnt in earlier lectures and will be able to explain how to detect and correct errors.
1. In a 4 bit system, 0000 to 0111 can be used to positive numbers from +0 to ____
and represent ___________ can be used for negative numbers from -0 to -2n-1
Ans: +2n-1 , 1000 to 1111
2. Each position is __ times more significant than the previous position for octal numbers.
Ans: 8
3. The ___ of an 8-bits word is used as the parity bit and the remaining 7 bits are used as data
or message bits.
Ans: MSB
Module 1: Number Systems and Codes 26
1. Represent (19)10in
i) 1's complement representation
ii) 2's complement representation
3. Add the two numbers (AC)H and (D9)H directly. Convert the hexadecimal system obtained,
in a number system with radix four.
https://www.tutorialspoint.com/computer_logical_organization/digital_number_system.ht
m
https://www.slideshare.net/fvsandoval/number-systems-basic-concepts-
180167272?qid=297b3b1e-be5a-414e-ad46-48fad0baed4d&v=&b=&from_search=6
1.16 Websites
https://www.tutorialspoint.com/
https://www.slideshare.net/
Self-assessment