KEMBAR78
DLD Module 1 | PDF | Digital Signal | Binary Coded Decimal
0% found this document useful (0 votes)
26 views26 pages

DLD Module 1

Module 1 covers number systems and codes, emphasizing the importance of understanding various number systems like binary, octal, and hexadecimal for computer architecture. It highlights the role of digital circuits in modern technology and the advantages of digital signals over analog signals, including noise resistance and programmability. The module aims to equip students with knowledge about number systems, arithmetic operations, and coding techniques for reliable communication.

Uploaded by

1O132 Samarth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views26 pages

DLD Module 1

Module 1 covers number systems and codes, emphasizing the importance of understanding various number systems like binary, octal, and hexadecimal for computer architecture. It highlights the role of digital circuits in modern technology and the advantages of digital signals over analog signals, including noise resistance and programmability. The module aims to equip students with knowledge about number systems, arithmetic operations, and coding techniques for reliable communication.

Uploaded by

1O132 Samarth
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Module 1: Number Systems and Codes 1

Module 1

NUMBER SYSTEMS AND CODES


1.1 Brief Background:

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:

Module Contents Duration Self-study duration

Introduction to number system, types of number,


1 2
number systems inter conversions
1
Representation of negative numbers in 8 binary
1 2
system
Module 1: Number Systems and Codes 2

Binary Addition, Binary Subtraction using 1’s and 2’s


1 1
complement numbers

Introduction to Codes: Weighted & Non-weighted


codes, 8-4-2-1 BCD code, Excess-3 code, Gray code,
Error detecting and correcting code: Parity code,
1 2
Hamming code, and alphanumeric codes.

1.5 Summative Assessment weightage: 10 to 15Marks


1.6 Prerequisite:
Basic knowledge of mathematics.

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.

1.8 Learning Outcomes:


Students will be able to,
a) Understand number systems
b) How to represent negative numbers and perform arithmetic operations
c) Inter-conversion of number system
d) Identify various types of codes and perform operations on it.

1.9 Key notations:

N= Symbols
r= radix of the system
LSB= Least Significant Bit
MSB= Most Significant Bit

1.10 Key Definitions:

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.

1.11.2 Advantages of digital signals

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.

1.11.4 Creating a perquisite for Number Systems

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

1.11.5 To know about different types of Number Systems


Module 1: Number Systems and Codes 5

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

• Binary number system


• Octal number system
• Decimal number system
• Hexadecimal (Hex) number system

1)Binary Number System

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.

2)Octal number 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).

3) Decimal number system

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.

4) Hexadecimal number system

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.

Hexadecimals are used in the following:


Module 1: Number Systems and Codes 7

• 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.

Questions/Problems for practice –

1. List the advantages and disadvantages of Digital systems.

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.

Let’s check take away from the lecture

1. An Analog Signal is continuous in both ____ and _____.


a. Frequency, power
b. Time, amplitude
c. Modulation, waveform
d. Segments, packets
Ans: b

2. Analog circuits do not involve quantization of information into digital format.


a. True b. False
Ans: a

3. Temperature variation is a/an


a. Analog Quantity
b. Digital Quantity
c. Either of the two
d. None
Ans: a

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).

II. Binary Numbers

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.

III. Octal Numbers

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

IV. Hexadecimal Numbers

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.

Decimal Binary Octal Hexadecimal


0 0000 0 0
1 0001 1 1
2 0010 2 2
3 0011 3 3
4 0100 4 4
5 0101 5 5
6 0110 6 6
7 0111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
Table 1.1: Relationship between decimal, binary, octal and hexadecimal numbers

1.11.6 Negative Number representation

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

Complementing bits will result


Module 1: Number Systems and Codes 10

10001000
+1 add 1
10001001
that is 10001001 2 = - 119 10

Properties of Two's Complement Numbers


1. X plus the complement of X equals 0.
2. There is one unique 0.
3. Positive numbers have 0 as their leading bit (MSB); while negatives have 1 as their MSB.
4. The range for an n-bit binary number in 2's complement representation is from -2 (n-1) to
2 (n-1) - 1
5. The complement of the complement of a number is the original number.
6. Subtraction is done by addition to the 2's complement of the number.

Value of Two’s Complement Numbers


For an n-bit 2's complement number the weights of the bits is the same as for unsigned
numbers except of the MSB. For the MSB or sign bit, the weight is -2 n-1. The value of the n-
bit 2's complement number is given by:
A 2's-complement = (a n-1) x (-2 n-1) + (a n-2 ) x (2 n-1 ) + ... (a 1) x (2 1 ) + a 0
For example, the value of the 4-bit 2's complement number 1011 is given by:
= 1 x -2 3 + 0 x 2 2 + 1 x 2 1 + 1
= -8 + 0 + 2 + 1
= -5

Let’s check take away from the lecture

1. The decimal equivalent of (1101010)2 is


a. 107 b. 105 c.106 d.108
Ans: c

2. 101 + 101 is
a. 0101 b.202 c.1110 d. 1010
Ans: d

3. Two’s complement of 011001 is


a. 111100 b.110011 c.111000 d.100111
Ans: d

4. The two’s complement of a 2’s complement binary number is


e. 1’s complement of the binary number
f. 2’s complement of the binary number
g. Original number
h. None
Ans: c

5. Given binary number is 00000111, its two’s complement in hexadecimal form is


a. F8 b. F9 c. 07 d.F0
Ans: b
Module 1: Number Systems and Codes 11

Questions/Problems for practice –

1. What is base of a number system?


2. Which number system uses numerals and alphabets?
3. How many bits are needed to count the number 255?
4. Which bit is used to represent sign in sign magnitude representation?
5.
6.
Learning from the topic: - Students will be able to distinguish between various types of numbers,
understand the concept of Two’s complement and convert numbers from binary to Gray codes and
vice versa.

Learning Objective: Students will learn how to perform Binary Arithmetic operations and how
to convert a number from one system to another.

1.11.7 Binary Arithmetic

I. Binary Addition

Rules of Binary Additiion


0+0=0
0+1=1
1 + 0 =1
1 + 1 = 0, and carry 1 to the next most significant bits
Example:
1. 00011010 + 00001100 = 00100110
1 1 carries
0 0 0 1 1 0 1 0 = 26 (base 10)
+ 0 0 0 0 1 1 0 0 =12(base 10)
_______________________________
0 0 1 0 0 1 1 0 = 38(base 10)
________________________________

2. 00010011 + 00111110 = 01010001


1 1 1 1 1 carries

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)

__________________________

Perform the following operations:


1. 00100101 + 00010001
Module 1: Number Systems and Codes 12

2. 00001000 +00000011

II. Binary Subtraction

Rules of Binary Subtraction


0-0=0
0 - 1 = 1, and borrow 1 from the next more significant bit
1-0=1
1-1=0

Example:

1. 00100101 - 00010001 = 00010100

III. Binary Multiplication

Rules of Binary Multiplication


0x0=0
0x1=0
1x0=0
1 x 1 = 1, and no carry or borrow bits

Examples:

Perform the following operations:


1. 00010111 × 00000011
2. 00001000 × 00000011
Module 1: Number Systems and Codes 13

IV. Binary Division

Binary division is the repeated process of subtraction, just as in decimal division.

Example

Perform the following operations:


1. 10000111 ÷ 00000101
2. 00001000 ÷ 00000011

V. Number Base Conversions


This section describes the conversion of numbers from one number system to another. Radix
Divide and Multiply Method is generally used for conversion. There is a general procedure
for the operation of converting a decimal number to a number in base r. If the number
includes a radix point, it is necessary to separate the number into an integer part and a
fraction part, since each part must be converted differently. The conversion of a decimal
integer to a number in base r is done by dividing the number and all successive quotients by r
and accumulating the remainders. The conversion of a decimal fraction is done by repeated
multiplication by r and the integers are accumulated instead of remainders.
Integer part - repeated divisions by r yield LSD to MSD
Fractional part - repeated multiplications by r yield MSD to LSD
Example:Conversion of decimal 23 to binary is by divide decimal value by 2 (the base) until
the value is 0

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.

Thus (23.7854) 10 = (10111. 1100) 2

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)

010 101 110 (binary)

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.

More Solved Examples

1. Convert (5A) H * (5B) H (MAY 2011)


Module 1: Number Systems and Codes 15

Soln: (5A)H= (80 +10)10 =90


(5B)H = ( 80+11) 10 =91
(5A) H * (5B) H = (8190) 10
Converting (8190)10 into hexadecimal number
8190/16= 511.875 0.875 * 16 =14 E (LSB)
511/16 = 31.9375 0.9375 * 16 = 15 F
31/16 = 1.9375 0.9375 * 16 = 15 F
1/16 = 0.0625 0.0625 *16 =1 1 (MSB)
(5A) H * (5B) H= (1FFE) 16
2. Convert (43)8 into hexadecimal number system

Let’s check take away from the lecture

1. Conversion from decimal to hex requires repeated division by


a.16 b. 2 c. 8 d.1
Ans: a
3. Conversion from decimal to which conversion requires repeated division by 8
a. Hexadecimal b. Octal c. Decimal d. binary
Ans: b

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

Questions/Problems for practice –

1. Convert the decimal number 172.876 to octal number


2. Convert the following binary number to octal number.
(i) 1101.00101
(ii) 1011011.011 011
3. What is the largest decimal number that can be represented by 16-bit binary word?
4. What are the applications of binary number system?
5. Perform the following conversions:
i. 40 from decimal to octal number
ii. Convert DF from hex to decimal number
iii. (11011.11)2 to decimal number
iv. (A4F)16 to Octal number
6. Subtract (101)2 from (1011)2 using 2’s complement.
7. Subtract (1101)2 from (1111)2 using 1’s complement.
8. Convert the following to Decimal and then to Hexadecimal.
a. (765)8
b. (1002)8
c. (11001001)2
d. (11110000)2
e. (257)10
f. (239)10

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

Advantages of Binary Code

Following is the list of advantages that binary code offers.

• Binary codes are suitable for the computer applications.


• Binary codes are suitable for the digital communications.
• Binary codes make the analysis and designing of digital circuits if we use the binary codes.
• Since only 0 & 1 are being used, implementation becomes easy.
Classification of binary codes

Binary
codes

Non Error detecting


Weighted Alphanumeric & Correcting
weighted

BCD or
2421 5211 Excess-3 Gray ASCII HOLLERITH EBCDIC Parity Hamming
8421

Figure 1.1: Classification of binary codes

The codes are broadly categorized into following four categories.

• 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.

Figure 1.2: Decimal to Weighted code

a. Binary Coded Decimal (BCD) code or 8421 Code


In this code each decimal digit is represented by a 4-bit binary number. BCD is a way to
express each of the decimal digits with a binary code. In the BCD, with four bits we can
represent sixteen numbers (0000 to 1111). But in BCD code only first ten of these are used
(0000 to 1001). The remaining six code combinations i.e. 1010 to 1111 are invalid in BCD.

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

Decimal Binary BCD

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

Advantages of BCD Codes

• It is very similar to decimal system.


• We need to remember binary equivalent of decimal numbers 0 to 9 only.

Disadvantages of BCD Codes

• The addition and subtraction of BCD have different rules.


• The BCD arithmetic is little more complicated.
• BCD needs more number of bits than binary to represent the decimal number. So BCD is
less efficient than binary.

b. 2421 code
The weights of this code are 2, 4, 2 and 1.

Decimal Binary 2421 Code

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.

Decimal Binary 5211 Code

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

Table 1.4: Binary and 5211 code equivalent of Decimal numbers

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

Decimal BCD Excess-3


8421 BCD + 0011
0 0000 0011
1 0001 0100
2 0010 0101
3 0011 0110
4 0100 0111
5 0101 1000
Module 1: Number Systems and Codes 20

6 0110 1001
7 0111 1010
8 1000 1011
9 1001 1100

Table 1.5: BCD 8421 and Excess-3 equivalent of Decimal numbers

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.

Decimal Binary Gray


0 0000 0000
1 0001 0001
2 0010 0011
3 0011 0010
4 0100 0110
5 0101 0111
6 0110 0101
7 0111 0100
8 1000 1100
9 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000
Table 1.6: Binary and Gray equivalent of Decimal numbers

Converting Gray Code to Binary

i. Write down the number in gray code.


ii. The most significant bit of the binary number is the most significant bit of the gray
code.
iii. Add (using modulo 2) the next significant bit of the binary number to the next
significant bit of the gray coded number to obtain the next binary bit.
iv. Repeat step C till all bits of the gray coded number have been added modulo 2.
v. The resultant number is the binary equivalent of the gray number.

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.

Binary corresponding to gray code 1010 is 1100.

Converting Binary to Gray

i. Write down the number in binary code.


ii. The most significant bit of the gray number is the most significant bit of the binary
code.
iii. Add (using modulo 2) the next significant bit of the binary number to the next
significant bit of the binary number to obtain the next gray coded bit.
iv. Repeat step C till all bits of the binary coded number have been added modulo 2
v. The resultant number is the gray coded equivalent of the binary number

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.

Application of Gray code

• Gray code is popularly used in the shaft position encoders.


• A shaft position encoder produces a code word which represents the angular position of
the shaft.
C. Alphanumeric codes

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.

• American Standard Code for Information Interchange (ASCII).

• Extended Binary Coded Decimal Interchange Code (EBCDIC).

• 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.

D. Error Detecting and correcting codes

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

Figure 1.3: Representation of error

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.

Parity Checking of Error Detection

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

Use of Parity Bit

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).

Figure 1.4: Representation of even and odd parity

How Does Error Detection Take Place?

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

Lets check take away from the lecture

1. Which of the following is not an invalid BCD code?


a) 1001
b) 1010
c) 1100
d) 1101

2. In BCD, the decimal number 257 is represented as


a) 001011010111
b) 001001010111
c) 001001010011
d) 001001011111

3. The 4 bit Gray code for decimal number 7 is


a) 0101
b) 0110
c) 0100
d) 0111

4. Convert BCD 0001 0010 0110 to binary


a) 1111110
b) 1111100
c) 1111010
d) 1111111

Questions/Problems for practice –

1. What is the full form of ASCII?


2. What do you mean by alphanumeric codes?
3. What is the binary equivalent of ‘A’ in ASCII code?
4. What do you mean by even and odd parity?
5. Encode the following decimal numbers in BCD code. A)64 B) 525.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.12 Objective Questions

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.13 Short Questions

1. Convert (268.75)10 to Octal & Hexadecimal?


2. Convert the following base 8 numbers to base 2
i)76, ii) 457
3. Determine equivalent decimal numbers for the following binary numbers:
i) 1001.1101 ii) 1100.0110

1.14 Long Questions

1. Represent (19)10in
i) 1's complement representation
ii) 2's complement representation

2. (1000) sign magnitude = (?)10


(1000) one's complement = (?)10
(1000) two's complement = (?)10

3. Add the two numbers (AC)H and (D9)H directly. Convert the hexadecimal system obtained,
in a number system with radix four.

1.15 Learning Resources

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

1. Perform the following operations directly without converting to decimal.


i) (C9)H - (8D) H
ii) (232)4 x (12)4
iii) (257)8 + (423)8
iv) (ll01001) 2 + (101) 2
2. Perform the following division: (11001101.111)2 x (110)2

You might also like