Chapter 1

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15

Chapter One

Number Systems and Codes

1. Number Systems and Codes


1.1. Introduction to computer system and its sub modules.
Representation of Basic Information
The basic functional units of computer are made of electronics circuit and it works with
electrical signal. We provide input to the computer in form of electrical signal and get the
output in form of electrical signal.
There are two basic types of electrical signals, namely, analog and digital. The analog signals
are continuous in nature and digital signals are discrete in nature. The electronic device that
works with continuous signals is known as analog device and the electronic device that works
with discrete signals is known as digital device. In present days most of the computers are
digital in nature and we will deal with Digital Computer in this course.
Computer is a digital device, which works on two levels of signal. We say these two levels of
signal as High and Low. The High-level signal basically corresponds to some high-level signal
(say 5 Volt or 12 Volt or 3.3 Volt) and Low-level signal basically corresponds to Low-level signal
(say 0 Volt). This is one convention, which is known as positive logic. There are others
convention also like negative logic. (Have you heard that computers take negative volt?). Since
Computer is a digital electronic device, we have to deal with two kinds of electrical signals. But
while designing a new computer system or understanding the working principle of computer, it
is always difficult to write or work with 0V or 5V.
To make it convenient for understanding, we use some logical value, say,
                        LOW (L)   -   will represent    0V and
                        HIGH (H)   -   will represent    5V

Computer is used to solve mainly numerical problems. Again it is not convenient to work with
symbolic representation. For that purpose we move to numeric representation. In this
convention, we use 0 to represent LOW and 1 to represent HIGH.
                                              0     means    LOW
                                              1     means    HIGH
To know about the working principle of computer, we use two numeric symbols only namely 0
and 1. All the functionalities of computer can be captured with 0 and 1 and its theoretical
background corresponds to two valued Boolean algebra.
With the symbol 0 and 1, we have a mathematical system, which is knows as binary number
system. Basically binary number system is used to represent the information and manipulation
of information in computer. This information is basically strings of 0s and 1s. (Everything needs
to be converted to strings of 0 and 1 to be processed in the computer)
The smallest unit of information that is represented in computer is known as Bit (Binary Digit),
which is either 0 or 1. Four bits together is known as Nibble, and Eight bits together is known as
Byte.

Computer Organization and Architecture


1
Computer technology has made incredible improvement in the past half century. In the early
part of computer evolution, there were no stored-program computer, the computational
power was less and on the top of it the size of the computer was a very huge one. Today, a
personal computer has more computational power, more main memory, more disk storage,
smaller in size and it is available in affordable cost.
This rapid rate of improvement has come both from advances in the technology used to build
computers and from innovation in computer design. In this course we will mainly deal with the
innovation in computer design.
The task that the computer designer handles is a complex one: Determine what attributes are
important for a new machine, and then design a machine to maximize performance while
staying within cost constraints. This task has many aspects, including instruction set design,
functional organization, logic design, and implementation.
While looking for the task for computer design, both the terms computer organization and
computer architecture come into picture. It is difficult to give precise definition for the terms
Computer Organization and Computer Architecture. But while describing computer system, we
come across these terms, and in literature, computer scientists try to make a distinction
between these two terms.
Computer architecture refers to those parameters of a computer system that are visible to a
programmer or those parameters that have a direct impact on the logical execution of a
program. Examples of architectural attributes include the instruction set, the number of bits
used to represent different data types, I/O mechanisms, and techniques for addressing
memory.
Computer organization refers to the operational units and their interconnections that realize
the architectural specifications. Examples of organizational attributes include those hardware
details transparent to the programmer, such as control signals, interfaces between the
computer and peripherals, and the memory technology used. By the way, what does
TRANSPARENT mean?

Non need to worry if the concepts mentioned above are not clear at this point because In this
course, we will touch upon all those factors and finally come up with the concept how these
attributes contribute to build a complete computer system

Basic Computer Model and different units of Computer

The model of a computer can be described by four basic units in high level abstraction
which is shown in the next figure. These basic units are:

 Central  Processor  Unit


              
 Input  Unit
                 
 Output  Unit
                     
 Memory  Unit 

2
Basic Computer Model and different units of Computer

A. Central Processor Unit (CPU):

Central processor unit consists of two basic blocks:

o The program control unit has a set of registers and control circuit to
generate control signals.
o The execution unit or data processing unit contains a set of registers for
storing data and an Arithmetic and Logic Unit (ALU) for execution of
arithmetic and logical operations.

In addition, CPU may have some additional registers for temporary


storage of data.

B. Input Unit:

With the help of input unit data from outside can be supplied to the computer.
Program or data is read into main storage from input device or secondary
storage under the control of CPU input instruction.

Example of input devices: Keyboard, Mouse, Hard disk, Floppy


disk, CD-ROM drive etc.

C. Output  Unit :

With the help of output unit computer results can be provided to the user or it
can be stored in storage device permanently for future use. Output data from
main storage go to output device under the control of CPU output instructions.

Example of output devices: Printer, Monitor, Plotter, Hard Disk, Floppy Disk etc.

D. Memory Unit:

Memory unit is used to store the data and program. CPU can work with the
information stored in memory unit. This memory unit is termed as primary
memory or main memory module. These are basically semi conductor memories.

3
There are two types of semiconductor memories -

 Volatile Memory          : RAM (Random Access Memory).


 Non-Volatile Memory: ROM (Read only Memory), PROM (Programmable
ROM), EPROM (Erasable PROM), EEPROM (Electrically Erasable PROM).

Secondary Memory:
o There is another kind of storage device, apart from primary or main memory,
which is known as secondary memory. Secondary memories are non volatile
memory and it is used for permanent storage of data and program.
o Example of secondary memories:

Hard Disk,  Floppy Disk,  Magenetic Tape ------  These are magnetic devices,
CD-ROM ------  is optical device
Thumb drive (or pen drive) ------  is semiconductor memory.

Stored Program (Von Neumann) Computer:

The present day digital computers are based on stored-program concept introduced by Von
Neumann. In this stored-program concept, programs and data are stored in separate storage
unit called memories.

Central Processing Unit, the main component of computer can work with the information
stored in storage unit only.

In 1946, Von Neumann and his colleagues began the design of a stored-program computer at
the Institute for Advanced Studies in Princeton.This computer is referred as the IAS computer.

The structure of IAS computer is shown in Next Figure.

4
The IAS computer is having three basic units:

o The Central Processing Unit (CPU).


o The Main Memory Unit.
o The Input/Output Device.

Central Processing Unit:

This is the main unit of computer, which is responsible to perform all the operations. The CPU
of the IAS computer consists of a data processing unit and a program control unit.

The data processing unit contains a high speed registers intended for temporary storage of
instructions, memory addresses and data. The main actions specified by instructions are
performed by the arithmetic-logic circuits of the data processing unit.

The control circuits in the program control unit are responsible for fetching instructions,
decoding opcodes, controlling the information movements correctly through the system, and
providing proper control signals for all CPU actions.

The Main Memory Unit:

It is used for storing programs and data. The memory locations of memory unit are uniquely
specified by the memory address of the location. M(X) is used to indicate the location of the
memory unit M with address X.

The data transfer between memory unit and CPU takes place with the help of data register DR.
When CPU wants to read some information from memory unit, the information first brings to

5
DR, and after that it goes to appropriate position. Similarly, data to be stored to memory must
put into DR first, and then it is stored to appropriate location in the memory unit.

The address of the memory location that is used during memory read and memory write
operations are stored in the memory register AR.

The information fetched from the memory is an operand of an instruction, and then it is moved
from DR to data processing unit (either to AC or MQ). If it is an operand, then it is moved to
program control unit (either to IR or IBR).

Two additional registers for the temporary storage of operands and results are included in data
processing units: the accumulator AC and the multiplier-quotient register MQ.

Two instructions are fetching simultaneously from M and transferred to the program control
unit. The instruction that is not to be executed immediately is placed in the instruction buffer
register IBR. The opcode of the other instruction is placed in the instruction register IR where it
is decoded.

In the decoding phase, the control circuits generate the required control signals to perform the
specified operation in the instruction.

The program counter (PC) is used to store the address of the next instruction to be fetched
from memory.

Input Output Device:

Input devices are used to put the information into computer. With the help of input devices we
can store information in memory so that CPU can use it. Program or data is read into main
memory from input device or secondary storage under the control of CPU input instruction.

Output devices are used to output the information from computer. If some results are
evaluated by computer and it is stored in computer, then with the help of output devices, we
can present it to the user. Output data from the main memory go to output device under the
control of CPU output instruction.

Real Life Analogy:

A mother guides her daughter to cook food for lunch. The mother knows how to cook food
from her past experience while the daughter listen instruction from her mother and accomplish
it to cook today’s lunch. The mother sits in a chair looking carefully the daughter who performs
the real tasks for cooking food. The daughter puts the tools that are needed to cook today’s
lunch in a bench/table near to her. But now she is to add salt so the puts the salt container the
table very near to her. However, those tools that are not needed to cook today’s lunch are put
in the table far away. For example: the daughter brings an instruction from mother who says

6
“bring salt”, and then the daughter brings the salt container. Then “add salt” instruction is
fetched from mother where the daughter adds salt to the cooking food.

Based on the above analogy, determine the following points in real computer: Mother,
Mother’s knowledge of how to cook food, Daughter, Register, RAM, External Storage
(Hard disk), Instruction, data. Check your answer with the one provided below. A
student who gets all the answers understands this chapter perfectly. Try it by yourself
before looking into the answer.

Answer:

Mother = primary memory (RAM) which contain knowledge/instruction to cook food.

Mother’s knowledge of how to cook food = programmer write algorithm/code on how to cook
food

Daughter = CPU (interpreting mother’s instruction and accomplishing the real lunch
preparation actions)

Register = bench very near to daughter containing the data (salt) or instruction saying “add
salt”

RAM: bench near to daughter containing data needed for today’s lunch preparation

External Storage (Hard disk) = bench far away from daughter containing data for not needed
for today’s lunch, may be for breakfast or dinner.

Instruction: “bring salt”, “add salt”

Data: salt.

1.2. Number Systems


A number system is a language system consisting of an ordered set of symbols called digits with
rules defining addition, multiplication and other mathematical operations. It helps us in
counting and arithmetic with predefined symbols. A number system allows for a number (a
collection of digits) to have an integer part and a fractional part set apart by a radix point “.”

The base of a number system specifies the actual number of digits included in its order. The size
of the number symbols determine the base of the number system. Decimal system includes

7
0,1,2,3,4,5,6,7,8,9. Binary system includes 0 and 1. Computers use binary system. (Why? the
reason to be clear as the course goes on). Decimal is human (our) language while binary is
digital language. Since computers are digital devices it uses binary languages (or binary
systems).

In general:
Decimal (base 10 system): 0,1,2,3,4,5,6,7,8,9. (10 symbols) which Is human language
Binary (base 2 system): 0, 1 (2 symbols) which is computer (or digital language)
Hexadecimal (or hexal) system: (base 16 system):
0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F (16 symbols)
Octal (base 8 system): 0,1,2,3,4,5,6,7 ( 8 symbols):
Hexal and Octal systems are used to narrow the distance between human language (decimal
system) and digital systems. In other words, they are used to simplify our digital system so that
we can easily represent digital numbers in a very shorthand form. Note that base x system
always use x symbols (from 0 up to x-1). Also note that the more symbols a number system
has the fewer digits it will utilize for an equivalent number in other base.

For example:
(15)10 = (15)10  2 digits
= (1111)2  4 digits
= (F)16  1 digits

The positional nature of number system is very important. The number systems we use are in
weighted-positional notation.
 Decimal number system, symbols = { 0, 1, 2, 3, …, 9 }
 Position is important
o Example: (7594)10 = (7x103) + (5x102) + (9x101) + (4x100). The value of each
symbol is dependent on its type and its position in the number.
In general, (anan-1… a0)10 = (an x 10n) + (an-1 x 10n-1) + … + (a0 x 100)
 Fractions are written in decimal numbers after the decimal point.
(2.75)10 = (2 x 100) + (7 x 10-1) + (5 x 10-2)
In general,

The number systems of our focus are:


Decimal system: because it is our native language
Binary system: because it is the number system of digital languages like computers
Octal and Hexal: because they are used to simplify the binary number system in to fewer
digits. Next we cover further understanding of the common number systems in the context of
value and sign through understanding of conversion process.

1.3. Number And Base Conversion


1.3.1. Any Base (Base R) - to - Decimal conversion
• Binary (base 2): weights in powers-of-2.
Binary digits (bits): 0,1.
• Octal (base 8): weights in powers – of -8.
Octal digits: 0,1,2,3,4,5,6,7.
• Hexadecimal (base 16): weights in powers-of-16.
Hexadecimal digits: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F.

8
• Base R: weights in powers-of-R.
(1101.101)2 = 1´23 + 1´22 + 1´20 + 1´2-1 + 1´2-3= 8 + 4 + 1 + 0.5 + 0.125 = (13.625) 10
(572.6)8 = 5´82 + 7´81 + 2´80 + 6´8-1 = 320 + 56 + 16 + 0.75 = (392.75)10
(2A.8)16 = 2´161 + 10´160 + 8´16-1 = 32 + 10 + 0.5 = (42.5)10
(341.24)5 = 3´52 + 4´51 + 1´50 + 2´5-1 + 4´5-2 = 75 + 20 + 1 + 0.4 + 0.16 = (96.56) 10

1.3.2. Decimal-to-Binary Conversion


Step 1: Break the number in two parts: Whole number and fraction part.
Step 2: Repeated Division-by-2 Method (for whole numbers)
Step 3: Repeated Multiplication-by-2 Method (for fractions)
 To convert a whole number to binary, use successive division by 2 until the quotient is
0. The remainders form the answer, with the first remainder as the least significant bit
(LSB) and the last as the most significant bit (MSB). (43)10 = (101011)2

 To convert decimal fractions to binary, repeated multiplication by 2 is used, until the


fractional product is 0 (or until the desired number of decimal places). The carried
digits, or carries, produce the answer, with the first carry as the MSB, and the last as the
LSB.
Example 1: (77.25)10 = (1001101.01)2

Example 2: (0.3125)10 = (.0101)2

Summary: conversion between bases


 Base-R to decimal: multiply digits with their corresponding weights.
 Decimal to binary (base 2)
o whole numbers: repeated division-by-2
o fractions: repeated multiplication-by-2
 Decimal to base-R
o whole numbers: repeated division-by-R
o fractions: repeated multiplication-by-R
1.3.3. Binary-Octal/Hexadecimal Conversion
Notice the following points when you do binary to octal conversion.
 Three binary digits make one octal digit.
 Putting zero to the left of a given number or right of the fractional part makes no
change in value.
o For example:
000…453=453

9
6.2400000…=6.24
 Rule: to the left of the radix point group each 3 binary digits and convert it to
octal; if a group of three can’t be fulfilled add zero to the left until fulfilled. To the
right of the radix point, group each 3 binary digits and convert it to octal, if a group
to three can’t be fulfilled, add zero digits to the right until fulfilled.
Example: (1001.1000011)2=(?)8
=001 001.100 001 100
=(11.414)8
Exercise: (1001001111.0000110001110) 2=(?)8
Ans=(1117.0307)8
Notice the following points when you do octal to binary conversion.
 1 octal digit will be converted to exactly 3 binary digits
 Rule: convert each octal digits into 3 binary digits.
Example: (123.3005)8=(?)2
=(001 010 111.011 000 000 101) 2
Exercise: (7113.7701)8=(?)2
Ans: (111001001011.111111000001)2
Notice the following points when you do binary to hexal conversion.
 Four binary digits make one octal digit.
 Putting zero to the left of a given number or right of the fractional part makes no
change in value.
o For example:
000…453=453
6.2400000…=6.24
 Rule: to the left of the radix point group each 4 binary digits and convert it to
hexal; if a group of four can’t be fulfilled add zero to the left until fulfilled. To the
right of the radix point, group each r binary digits and convert it to hexal, if a group
to four can’t be fulfilled, add zero digits to the right until fulfilled.
Notice the following points when you do hexal to binary conversion.
 1 hexal digit will be converted to exactly 4 binary digits
 Rule: convert each hexal digit into 4 binary digits.

Note: students are expected to practice hexal/binary conversion based on examples provided
for octal/binary conversion.
Summary: conversion between bases
 Binary to Octal: Partition in groups of 3
(10 111 011 001. 101 110)2 = (2731.56)8
 Octal to Binary: reverse the above step
(2731.56)8 = (10 111 011 001. 101 110)2
 Binary to Hexadecimal: Partition in groups of 4
(101 1101 1001. 1011 1000)2 = (5D9.B8)16 = 0x5D9.B8
 Hexadecimal to Binary: reverse of the above step
(5D9.B8)16 = (101 1101 1001. 1011 1000)2

10
Table: Conversion map of common number systems. Try to remember this table, knowing it by
heart simplify a lot in the conversion process though it is possible to calculate this table by
simple conversion calculations discussed earlier.

Decimal Octal Hexal Binary


0 0 0 0
1 1 1 1
2 2 2 10
3 3 3 11
4 4 4 100
5 5 5 101
6 6 6 110
7 7 7 111
8 10 8 1000
9 11 9 1001
10 12 A 1010
11 13 B 1011
12 14 C 1100
13 15 D 1101
14 16 E 1110
15 17 F 1111
1.4. Binary Arithmetic
The binary number system that we have seen in relation to conversion does have no
arithmetic usage as it focused on value. Any number system should at least have a
signed number system representation to provide arithmetic usage. Can you guess
why?
Arithmetic operations are:
 Addition (+)
 Subtraction(-)
 Multiplication(*)
 Division(/)
Numbers should have not only value but also sign i.e., positive and negative. But we
have not positive and negative in machine. Therefore, the symbols of the binary
number system should have the capability to provide ‘sign’ representation. Remember
always that digital machines (including computers) speak always in 0’s and 1’s and
there is no exception for sign; too). This means we must represent signs (positive and
negative) in binary digits too. Unsigned binary arithmetic, though not common, will be
clarified in the next section, in parallel with signed number representation.

1.5. Binary Signed Number Representation


The approach we follow to discuss the signed number binary arithmetic has three
steps. In each step, we follow a systematic approach that shows the disadvantage of

11
each step and how the next step tries to solve the weakness of the previous. The
steps are:
I. Discuss a number of signed number representations (at least three)
II. Test each representation with a known calculation (using our previous decimal
number system knowledge) with strength and weakness of each representation.
III. For all our discussion, assume a fixed width 8 bit binary machine with the left
most bit representing the sign. Bits mean Binary digit (which is 0 or 1).This
means all numbers are assumed to be represented in 8 bits. More about this in
later chapters.

An 8 bit fixed width number is symbolically represented as XXXXXXXX where X


represents a binary digit which is 0 or 1 (because we are using binary number
representation). In binary number representation, the universal truth that should not
be forgotten is a binary digit ‘1’ always represents negative and a binary digit ‘0’
always represent positive.

Now, let’s see the three most common signed number representations.
1) Sign magnitude representation.
2) 1’s complement (ones complement) representation.
3) 2’s complement (twos complement) representation.
The third (2’s complement) is the widely accepted and currently universal
representation used in binary number system. The reason will be discussed later.

1) Sign magnitude representation.


The left most bit (1 bit) represents sign. Don’t forget that ‘1’ always represents
negative and ‘0’ always represent positive. The rest of the bit represents value
(magnitude). What range of numbers represented with this notation?
Based on this binary number system,
+3=00000011
-5=10000101
+126=01111110
-127=11111111
+254=no representation because with 8 bit fixed width signed magnitude
representation we can only represent numbers from -127 (11111111) to +127
(01111111).

In unsigned number representation (where all bits are used for value) number
representation
+3=00000001
-5= no representation for negative numbers
+126=01111110
-127=no representation for negative numbers
+254=11111110

12
1024=no representation because in 8 bit fixed width unsigned number
representation. We can only represent number from 0 (0000000) to 255 (11111111)

Problems of signed magnitude representation: there are two zeros, but we actually
have only one zero.
+0=0000000
-0=10000000
Now let’s check the usability of signed magnitude representation through arithmetic
examples.
a. 3 + 4 = (+3) + (+4)
= 00000011 +
00000100
= 00000111
=+7 which is a correct result. (it works when all numbers are positive
b. 3 – 4 = 3 + (-4)
=00000011 +
10000100
=10000111
= -7 which is the wrong answer.
c. 4 – 3 = 4 + (-3)
=00000100 +
10000011
=-7 which is again a wrong answer

d. -3 – 4 = (-3) + (-4)
=10000011 +
10000100
=100000111 the left most bit is the overflow, rejecting it gives
=00000111
=+7 again wrong answer.
What about -127 – 127?
This approach has several wrong answers.
Important note: the computer knows 0 and 1, it doesn’t know the sign, and the sign
should also be represented in 0 and 1. Moreover, subtraction should
be defined in terms of addition of signed numbers. You can’t have
subtraction without signed number representation.
2) 1’s complement
 Positive number is exactly the same as sign numbers
 Negative number is the complement of the negative number.
 Complement of 1 is 0 and complement of 0 is 1. Symbol of complement
is ‘.
Example: +4=00000100
-4=(+4)’=(00000100)’
= 11111011

13
-3=(+3)’=(00000011)’
=11111100
 To read a number
 If the first bit is zero, put positive and take the remaining bits as
magnitude
 If the first bit is one, first invert the remaining bits and take
them as a value with negative prefix.
Example:
a) 3 + 4 , students are expected to check this gives the correct result.
b) 3 – 4 = 3 + (-4)
= 00000011 +
11111011
= 11111110
= -1 which is a correct answer
c) 4 – 3 = 4 + (-3)
= 00000100 +
11111100
= 100000000 the left most bit is overflow, bring it add to the rest of the
value.
= 00000000 +
1
= 00000001
=+1 which is correct answer. But it is difficult to handle end around
carry in reality.

d) -4 -3 = (-3) + (-4)
= 11111011 +
11111100
=100000111 then handling the end around carry gives
= 00000111 +
1
=11111000
= -7 which is the correct answer , but still end around carry.

Success of 1’s complement:


 gives correct answers for all possibilities including those failed with signed
magnitude
Failures are:
 Handling end around carry is difficult.
 Still two zeros exist.
o 00000000 = +0
o 11111111 = -0

3) 2’s complement
14
 Positive numbers same as sign magnitude and 1’s complement
 Negative numbers = (positive representation)’ +1
 Positive numbers read as just like 1’s complement
 To read negative numbers (first bit 1), take the complement of the rest of
bits and add 1 to it.
Example: -4 = (00000100)’ + 1
= 11111011 + 1
= 11111100 (how do you read/interpret this number)
-3 = (00000011)’ +1
= 11111100 + 1
= 11111101
Success of 2’s complement
 There is only one zero
o 00000000 = +0
o 11111111 = -1
 There is no end around carry, if overflow occurs just discard it. Discarding
carry is easier than end around carry.

Now let’s check the correctness of 2’s complement with arithmetic.


a) 3 + 4, students are expected to check for this case.
b) 3 – 4 = 3 + (-4)
= 00000011 +
11111100
= 11111111
= -1 which is the correct answer
c) 4 – 3 = 4 + (-3)
= 00000100 +
11111101
= 100000001 the left most bit is discarded
= 00000001
= 1 which is the correct answer.
d) -4 -3 = (-4) + (-3)
= 11111100 +
11111101
= 111111001 the left most bit is discarded
= 11111001
= -7 which is the correct answer.
Final Point: because of the comparative advantages discussed above, 2’s complement
is the universally used signed number representation.

1.6. Binary Codes (Reading assignment)


Students are expected to read about binary codes: a motivated student may cover the
purpose, history, and application of ASCII and Unicode, BCD and EBCDIC, Gray code etc.

15

You might also like