CSC111

You might also like

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

CSC 111 – INTRODUCTION TO COMPUTER SCIENCE I

 Overview of the discipline of computer science


 General structure of a computer system
 Historical development of a computer science
 Generations of computer systems
 Computer operation
 Internal structure of computer hardware
 Introduction to the internet
 Computer appreciation (MS Word, Excel and Access Packages)
 Computer numbering system
 Computer arithmetic
 Computer data representation schemes
 Problem solving with computer

1
BACKGROUND OF ELECTRONIC COMPUTERS:

Electronic computers in the United States were developed in response to the need to
handle numerical computations related to the computation of Ballistics tables at the
Aberdeen Proving Grounds in Maryland.

The first electronic computer of note; the ENIAC (Electronic Numerical Integrator
and Calculator) was developed in the 1940’s at the University of Pennsylvania in the
United States of America (USA). This computer was quite big due to the
implementation technology- the vacuum tubes.

The ENIAC and other digital computers of this era (1935-1955) were large expensive
machines used by governments and large business. The size and shape of the digital
computer changed in the past few years owing to a new device called the
microprocessor. The micro processor is an integrated circuit (IC) that contains much
of the processing capabilities of a large computer. The microprocessor is a small but
extremely complex LSI (Large Scale Integration) device that is programmable.
In contrast, a microcomputer contains a microprocessor and at least some form of
semiconductor memory (RAM)
Computers are usually general purpose unit i.e. they are typically reprogrammed and
used for many jobs.
However, there are dedicated computers which are programmed for and performs
only one or two tasks as in toys, thermostats, microwave oven and automobiles.

2
COMPUTER HARDWARE
Definition:
Computer Hardware refers to the physical equipment which makes up the computer
system.

INTERNAL STRUCTURE OF A COMPUTER


The traditional sections of a digital computer are shown below:

Input CPU Output

Memory

The basic computer system consists of 5 units.- the input, the output, the arithmetic
and logic unit(ALU), the control unit and the memory. The Arithmetic and Logic
Unit(ALU)) and the Control Unit) are collectively called the CPU(Central Processing
Unit). These units are physical units referred to as hardware.

The input unit is responsible for converting information into electronic form; the
output unit is responsible for the inverse i.e. converting electronic signals back to
information. The arithmetic and logic unit is responsible for performing the arithmetic
and logic functions specified in instructions; the control unit is responsible for
retrieving instructions from memory, interpreting the instruction and providing
necessary signals to effect its execution. The memory(internal) unit is responsible for
storing programs and data being worked on by the CPU.
For a computer to be useful, a program stored in memory must tell the CPU what to
do. Preparing the list of instruction is called programming. The list of instructions is
stored either temporarily or permanently in the memory. The programs manipulate
information called data. If software is stored permanently in memory; it is sometimes
called firmware.

The computer works in the following manner; the program and data are fed into the
CPU and transferred to their respective memory locations. The CPU reads the first

3
instructions from memory and executes it. Instructions may be as simple as add two
numbers , move data, input or output data or jump to a different place in the program.
After the data manipulation are complete the result are transferred to the output of the
computer.

COMPUTER ORGANIZATION.

4
Figure 1

5
The organization of a typical microcomputer system is shown in Figure 1 above.
The CPU(microprocessor) controls all the units of the system using the control lines shown at
the left . Besides the control lines, the address bus (16 Parallel conductors) selects a certain
memory location, input port or output port. The data bus (eight parallel conductors) on the
right is a two way path for transferring data in and out of the Microprocessor Unit(MPU).
The microprocessor unit (MPU) can send data to or retrieve data from the memory using the
data bus. If a program is stored permanently, it is usually placed on a memory device called a
read-only memory (ROM). The ROM is usually a permanently programmed memory chip
(IC) ; temporary data is usually stored in an IC device called a Random Access Memory
(RAM). Microcomputer programs that are temporary in nature are also stored in RAM.

6
INTERNAL COMPUTER OPERATION

Figure 2

From figure 2, note that instructions have already been loaded into the first six memory
locations and it is determined that the instructions currently listed in program memory are.

7
1. Input data from port 1
2. Store data from port 1 in data memory location 200
3. Output data to output port 10

Note that instructions are usually broken into parts. The first part of instruction above
was to INPUT data. The second part tells from where the data come (i.e. from port 1).
The first section part of the instruction is called the operation and the second part is
called the operand. The operation and operand are located in separate memory
locations in program memory (figure 2)
Two new sections have been identified by the microprocessor in Figure 2. These two
sections are called register. These special registers are the accumulator and the
instruction register.
The flow of instructions and data will be followed by keying in the coded numbers in
the figure 2

Step 1: The MPU sends out address 100 on the bus.

Step 2: The program memory reads out the first instruction (input data and the MPU
accepts this coded message. The instruction is put in the instruction Register. The
MPU decodes (interprets) the instruction and determines that it needs the operand to
the input data instruction.

Step 3: The MPU sends out address 101 on the address bus. The control line enables
the read input of the memory.

Step 4: The memory places the operand (from port 1) on the data bus. This coded
message (the address for port 1) is accepted off the data bus and placed in the
instruction register.

Step 5: The MPU causes port 1 to open using the address and control lines to the input
unit. The coded form for A is transferred to and stored in the accumulator of the
MPU.

Fetch-Decode-Execute Cycle
It should be observed from the foregoing that the MPU first fetches the instruction,
second it decodes it (the instruction), thirdly, the MPU executes the instruction.

Step 6: The MPU sends location 102 on the address bus. The MPU enables the read
input on the memory using the control lines
.
Step 7: The code for the STORE data instruction is read onto the data bus and
accepted by the MPU in the instruction register
.

8
Step 8: The MPU decodes the STORE data instruction and determines that it needs
the operand. The MPU addresses the next memory location (103) and enables the
memory read input
.
Step 9: The code for “in memory location 200” is placed on the data bus into the
instruction Register (IR)

Step 10: The MPU sends out address 200 in the address and enables the write input of
the data memory.

Step 11: The MPU put the information stored in the accumulator on the data bus. The
A is written into location 200 in data memory.

Step 12: The MPU addresses location 104 and enable the read input of the program.

Step 13: The “output data” instruction code is placed on the data bus. The MPU
accepts the instruction in the instruction Register. The MPU decodes the instruction
and determines it needs on operand.

Step 14: The MPU places address 105 on the address bus and enables the read input
of program memory.

Step 15: The program memory puts the code for the operand “to port 10” on the data
bus. The MPU accepts the code in the instruction register
.
Step 16: The MPU decodes the entire instruction “OUTPUT data to port 10”. The
MPU address port 10 using the address bus and control lines to the output unit. The
MPU places the code for A on the data bus. The A is transmitted out of port 10 to the
CRT monitor.

Types Of Computer:

Computers are classified based on different criteria such as the underlying technology,
the size (speed), the generality of use etc. Here, we highlight these modes of
classification:

a) By underlying Technology:

Computers are classified as digital computers or analog computers based on the nature
of the signals under which it operates.

Digital computers are electrical devices. They are classified as digital if the signals in
which they operate are discrete. Modern computers are digital and operate in two
signals represented by 0 and 1. Therefore, they are said to be binary numbers.

9
Analog computers are based on continuous electrical signals. The use of digital
computers exceeds that of analog computers today.

A) Classification By Size And Relative Processing Power:

By 1980’s computers were classified as mainframe, mid-range and microcomputers.


To express the relative processing power and number of end users that can be
supported by the different types of computers.

Microcomputer Systems:

Microcomputers are usually called personal computers or PC. The computing power
of microcomputer now exceeds that for mainframes of previous computer generations
at a given fraction of their cost.

Minicomputer (mid range Computers)

Mid Range computers are larger in size and speed than microcomputers. They are
typically used as high-end servers that can manage network of PC’s and terminals.
Minicomputers are less costly to buy, operate and maintain than mainframe
computers. Minicomputers are characterized by short word size- CPU sizes of 8 and
16 units were typical- limited hardware and software facilities and small physical size.

The history of minicomputers can be traced to LINC (Laboratory Instrument


Computer) developed at MIT in the early 1960. This machine influenced the design
of the PDP (Program Data Processor) series of small computers in 1965, which
established he minicomputer market.

Mainframe Computers

The term “mainframe “ is applied to the traditional “large” computer system, often
containing thousands of IC’s and costing millions of dollars. It typically served s the
Central Processing Unit (CPU) facility for an organization such as a university, a
factory or a bank. Mainframes were then room sized machines placed in special
computer and not directly accessible to the average user. Today, mainframes can
process hundreds of millions of instructions per second (MIPS). Mainframes also
have large primary storage facilities. Their main memory can range from hundreds of
megabytes to many gigabytes storage.
Mainframes can handle the information processing needs of major corporations and
Government agencies with high transaction processing volumes or complex
computational problems. For example, major international banks, airlines and oil

10
companies, and other large corporations process millions of sales transactions and
customer inquiries each day with the help of mainframe systems.

Supercomputers:

Supercomputers are extremely powerful and expensive scientific computers. Control


Data Corporation, produced a series of commercially successful supercomputers
beginning with the CDC in 1964 nd continuing in the 1980’s with the cyber series.

The market for supercomputers includes Government research agencies, large


universities and major corporations. They use super computers for such applications
as global whether forecasting, military defence systems, computational cosmology
and astronomy, microprocessor research and design, large scale data mining and so
on.

Supercomputers use parallel processing architectures (which can execute many


instructions at the same time in parallel. They perform arithmetic calculations at speed
of billions of floating instructions per second (gigaflops). Supercomputers exist today
that can calculate at peta-flops (10 15) floating point operations per second; while exa-
flop (1018) computers floating point instructions per second are in view.

The classification of computers as mainframe, mini, and micro by size and capability
has changed over time i.e. the capabilities in terms of speed, storage capacity and size
which represented mainframe computers in the 80’s can now be found on
smartphones which can be regarded as todays microcomputers. In fact the idea of
super-computer has evolved to that of advanced computing system which embodies
the hardware, software and algorithms needed to deliver the very highest capability at
any time.
Just a few years ago, the very highest data storage contained only a few terbytes of
secondary storage. Today, commercial and research cloud computing systems each
contain many petabytes of secondary storage and individual labs routinely process
terabytes of data produced by their own scientific instruments. Atop this hardware, the
Apache Hadoop system implements a map reduce model for data analytics.

Evolution of Computer Technology:

Computer technology have passed through many stages characterized by relays and
vacuum tubes, transistors, Integrated Circuits- classified s small scale integrated
circuits (SSI), Large Scale Integrated Circuits (LSI) and Very Large Scale Integrated
Circuits (VLSI). Classification of computers based on the type of technology has been
termed computer generations.

First Generation

11
The first generation computers are based on vacuum tube, which grew rapidly in the
late 1940’s and early 1950’s. Besides their use of vacuum tubes in the CPU, first
generation computers experimented with various technologies for secondary memory.

Examples are the use of ferrite core memory in which a bit of information was stored
in magnetic form on a tiny ring of magnetic material. Ferrite core remained the
principal technology for main memories until the 1970’s.

The earliest computers had their instructions written in binary code known as machine
language that could be executed directly. An instruction in machine language meaning
“add the contents of two memory locations might take the form

00111011000000001001100100000111

Machine language is extremely difficult for humans to write, and so is error prone. A
substantial improvement is obtained by allowing operation and operand addresses to
be expressed in an easily understood symbolic language such as

ADD X1, X2

This symbolic format referred to as an assembly language came into use in the
1950’s. In spite of their design deficiencies the first generation computers produced
many features central to later computers; the use of a CPU with a small set of
registers, a small memory for instructions and data storage and an instruction set with
a limited range of operations and addressing capabilities.

The Second Generation:

The technology of the transistor typifies the second generation of computers. The
transistor serves s a high speed electronic switch for binary signals, but is smaller,
sturdier, cheaper and requires less power. The ferrite core memory was also
superceded by all transistor memory in the 1970’s. The second generation are typified
by computers manufactured between 1954 – 1964

Third Generation:

Third generation is usually associated with the introduction of integrated circuits


(IC’s) which first appeared commercially in 1961. The transistor continued to be the
basic switching device, but IC’s allowe large numbers of transistors and associated
components to be combined on a tiny piece of semiconductor material, usually
silicon. The third generation begun around 1965. The designation of computer by
generation largely fell into disuse after the third generation.

12
THE VLSI (Very Large Scale Integration Era)
The IC technology has evolved steadily from those containing just a few transistors
to those containing thousands of millions of transistors; the later case s termed Very
Large Scale Integration or VLSI. VLSI allows manufacturers fabricate a CPU, main
memory or even all electronic circuits on a single IC that can be manufactured at low
cost.

EXAMPLE:
What do you understand by VLSI in computer technology.
SOLUTION:
VLSI are integrated circuits containing thousands or millions of transistors on a chip
of silicon.

Integrated Circuits:

The integrated circuit was invented in 1959 at Texas Instruments (TI) and Fairchild
Corporation.

13
OVERVIEW OF COMPUTER SCIENCE

Computer science deals with computation both in theory and application. Central to
the study of computer science is the design of machines which aid computation especially
electronic computers, and the means of achieving computation i.e. algorithms.

The study of algorithms encompasses four distinct areas;

1. Machines for executing Algorithms


This area includes everything from the earliest pocket calculators to the largest
general purpose digital computer. The goal is the study of various forms of machine
fabrication and organization so that algorithms can be effectively carried out.
2. Language for describing Algorithms
The language for describing algorithms can be placed in a continuum. At one end are
the languages which are close to the actual machine and at the other end are languages
designed for problem solving. Often one distinguishes between two members of this
area language design and translation. Language design calls for methods for
specifying the syntax and semantics of a language. Language translation requires a
means of translation into a more basic set of instructions.
3. Foundations of Algorithms
In this aspect of computer science, people ask and try to answer questions such as; is a
particular task accomplishable by computing? What is the minimum number of
operations necessary for a computer to perform certain function? Abstract models of
computing are devised so that these properties can be studied.
4. Analysis of Algorithms
Whenever an algorithm can be specified one wonders about its behavior. This was
realized as far back as Charles Babbage (1796 - 1871), the Luscansian professor of
Mathematics at the University of Cambridge, the father of Computers. An algorithms
performance profile is measured in terms of memory space that are consumed, while
the algorithms speed is measured by its running time such as the average and worst
case running time.

In this definition of computer science “Algorithm” is the fundamental notion.

Definition
An algorithm is a finite set of instructions which if followed accomplishes a particular task.
In addition, every algorithm must satisfy the following criteria.
i. Input: There are zero or more quantities which are externally supplied.
ii. Output: At least one quality is produced.
iii. Definiteness: Each instruction must be clear and unambiguous.
iv. Finiteness: If we trace out the instructions of an algorithm for all cases, the algorithm
will terminate after a number of steps.
v. Effectiveness: Every instruction must be sufficiently simple it can be carried out by a
person using pencil and paper.

14
Before a machine such as a computer can perform a task an algorithm for performing
that task must be discovered and represented in a form that is compatible with the machine. A
representation of an algorithm is called a program. Therefore, there is a distinction between
an algorithm and a program. A program is an algorithm represented in a programming
language.

The process of developing a program, encoding it in machine compatible form and


inserting it into a machine is called Programming.

Programs and the algorithms they represent are collectively referred to as software, in
contrast to the computer itself, which is known as hardware.

The study of algorithms began as a subject in mathematics. Indeed, the search for
algorithms was a significant activity of mathematicians long before the development of
today’s computers. This gave rise to the Entcheingdungs (decision) problem, a project by
renounced mathematician David Hilbert in 1928 in which he sought to prove any
mathematical theorem using first order predicate logic. Once an algorithm for performing a
task has been found, the performance of that task no longer requires an understanding of the
principles on which the algorithm was based, the performance is reduced to the process of
merely following directions. In a sense, the intelligence required to solve the problem is
encoded in the algorithm.

We can construct a machine to perform a task only if an algorithm exists for


performing that task. In turn, if no algorithm exists for solving a problem that problem lies
beyond the capabilities of machine.

Identifying the limitations of algorithmic capabilities solidified as a subject in


mathematics in the 1950’s with the publication of Kurt Godel’s incompleteness theorem. The
incompleteness theorem was a solution to a long drawn attempt by David Hilbert to devise an
algorithm which, when given a formula in first order logic, would determine if it is valid or
not. First order logic is able to express theorems in mathematics, it was hoped it is possible to
manipulate logical formulas like algebraic symbols. The incompleteness theorem essentially
states that in any mathematical theory encompassing our traditional arithmetic system, there
are statements whose truth or falseness cannot be established by algorithmic means.

The realization shook the foundation of mathematics, and the study of algorithmic
capabilities that ensured was the beginning of the field of computer science.

Algorithms are used to solve problems in the following fields;

a) Data Processing:- Data processing deals with the transformation of our input data to
provide information for decision making. Data processing constitutes over 70% of the
application of computer in the industry. A major characteristic of data processing is
that it deals with extremely large volumes of data and usually, these large volumes of
data are integrated. An integrated agglomeration of data is called a database.
b) Computer Graphics:- Computer graphics is the branch of computer science that
applies computer technology to produce and manipulate visual representation. It is

15
associated with a wide assortment of topics including the presentation of text, the
construction of graphs and charts; the development of graphical user interface, the
manipulation of photographs, the production of videogames, and the creation of
animated motion pictures. The term computer graphics is increasingly being used in
reference to the specific field called 3D graphics.
c) Human Computer Interaction (HCI):- Human computer interaction focuses on the
design and use of interface between computers and people (Users). The term was
popularized in the seminal 1983 both by S.K. Card and Allen Newell of Carnegie
Mellon University in their 1983 book; The Psychology of Human Computer
Interaction.
d) Artificial Intelligence:- This field seeks to build autonomous machines – machines
that can carry out complex tasks without human interaction. This goal requires that
machines be able to perceive and reason.

The field of artificial intelligence has been accompanied by a vigorous debate


essentially from its very beginnings, “Alan Turning” addressed the issue of machine
intelligence in 1950 “Computing Machinery and Intelligence” where he proposed the
“imitation game” now known as the “Turning Test” as an operational definition for
machine intelligence. Turning carefully analyzed and rebutted arguments against
machine intelligence and stated “I believe that at the end of the century the use of
words and general educated opinion will be able to speak of machine thinking without
expecting being contradicted” this view as been contested by philosophers who
argued against the possibility of intelligent machine. However, today smart machines
now _______ our lighting tolls, check us out at the stores, take our blood pressure,
massage our back, etc. In fact it is predicted that by year 2045 machines will be able
to do if not any work humans can do, then a significant amount of the work humans
can do. Robotics is clearly going to be a very economic enabler perhaps as
transformative as the internet. (CACM July, 2013. Page 5).

16
PROBLEM SOLVING

Software refers to a collection of instructions, called a program that directs the


hardware; programs are written to solve problems or perform tasks on a computer.
Programmers translate the solutions or tasks into a language the computer can understand.

Performing a Task on the Computer

The first step in working instructions to carry out a task is to determine what the output
should be

The second step is to identify the data or input necessary to obtain the desired output.

The last step is to determine how to process the input to obtain the desired output. A pictorial
representation of this problem-solving process is

Input Processing Output

We determine what we want as output, get the needed input, and process the input to produce
the desired output

Example 1:

Rate = distance/time
The output desired is the rate of change of distance (called velocity)
The input: The distance covered
The time taken to cover the distance
The processing = distance/time

Example 2:
F = 1.8C + 32
Where F is the temperature in Fahrenheit
C is the temperature in Centigrade
Input: Temperature in Centigrade
Output: Temperature in Fahrenheit

Example 3:
C = 5/9(F-32)
Input: Temperature in Fahrenheit
Output: Temperature in Centigrade
Processing: 5 x (F-32)/9

Example 4:
Given, T = (C + 40)/10

17
Where, C is the number of chirps per minute
T is the temperature in Fahrenheit
Input C
Output T
Processing (C + 40)/10

ALGORITHM:

By 1950, the word algorithm was frequently associated with Euclid’s algorithm, which
is a process of finding the greatest common divisor.

EUCLID’S ALGORITHM

Given two positive integers m and n, find their greatest common divisor i.e. the
largest integer which divides both m and n.

E1 [find Remainder] Divide m and n and let r be the remainder (we will have 0 < r <
n)

E2 [Is it zero?], if r = 0, the algorithm terminates, n is the answer.

E3 [Interchange] Set m ← n, n ← r, go back to step E1.

The above style of presenting an algorithm is explained below:

Each algorithm will be given an identifying letter (e.g. E above), the steps of the
algorithm are identified by this letter followed by a number (e.g. E1, E2 etc)

Each step of an algorithm begins with a phrase in brackets which sums up as briefly
as possible the principal content of that step.

The “←” arrow in step E3 is the replacement operation (sometimes called assignment
or substitution) “m ← n” means the value of variable m is to be replaced by the
current value of n. in general, “variable ← formula” means the formula is to be
computed using the present values of any variables appearing within it, and the result
replaces the previous value of the variable at the left of the arrow.

Note that the order of the actions in step E3 is important; set m ← n, n ← r” is quite
different from “set n ← r, m ← n”, since the latter would imply that the previous
value of n is lost before it can be used to set m. When several variables are all to be
set equal to the same quantity, we use multiple arrows, thus “n ← r, m ← r” may be
written as n ← m ← r. To interchange values of two variables are can write
“Exchange m ↔ n; this action may also be specified by using a new variable t and
writing “set t ← m; m ← n, n ← t.

18
An algorithm starts at the lowest numbered step, usually step 1, and steps are executed in
sequential order, unless otherwise specified. In step E3, the imperative “go back to step E1”
specifies the computational order in an obvious fashion. In step E2, the action is preceded by
the condition “if r = 0”, so if r ≠ 0, the rest of the sentence does not apply and no action is
carried out.

Flowcharts

A flowchart consists of special geometric symbols connected by arrows. Within each


symbols is a phase representing the activity at the step. The shape of the symbol indicates the
type of operation that is to take place. The arrows connecting the symbols, called flow-lines,
show the sequence the steps take place. Although, the symbols used on flowcharts are
standardized, no standard exist for the amount of detail required within each symbol.

Below is a table of flowchart symbols adopted by the American National Standards


Institute (ANSI)

Symbol Name Meaning


Flow-line Used to connect symbols and indicate the
flow of logic
Terminal Used to represent the beginning or end of a
task
Input/output Used for input/output operations, such as
reading and printing
Processing Used for arithmetic and data
_____________________ operations
Decision Used for any logic or comparison
operations
Connector Used to join different flow-lines

Predefined Process Used to represent a group of statements


that perform a task
Annotation Used to provide additional information
about another flowchart symbol.

PSEUDO CODE

Pseudocode is a middle ground between purely verbal description in paragraph form


and a computer program written in a programming language. An algorithm in pseudo code
should not be hard to understand even if you know nothing about computer programming.

Pseudo code has several advantages. It is compact and not extended for many pages.
Also, the plan looks like the code to be written and is preferred by many programmers.

19
The problems we have looked at so far were solved by a series of instructions to read
data, perform calculations and display the result. Each step was in a sequence; that is we
moved from one line to the next without skipping over any lines. This kind of structure is
called Sequence Structure.

DECISION STRUCTURE

Many problems require a decision to determine whether a series of instruction should


be executed. If the answer to a question is ‘yes’ then one group of instructions is executed. If
the answer is ‘no’, then another group is executed. The figure below contains the pseudo code
and flowchart for a decision structure.

IF condition is true THEN

Process step(s) 1
Is
ELSE condition
true?
Process step(s) 2

END IF
Process Process
step(s) 2 step(s) 1

Flowchart for decision structure

A) Pseudo code for decision structure

20
LOOP STRUCTURE

A loop structure is a programming structure that executes the instructions many times. In a
loop structure we use a test to tell when the loop should end. Without an exit condition, the
loop will repeat endlessly (an infinite loop). One way to control the number of times a loop
repeats (called the number passes or iteration) is to check a condition before each pass
through the loop and continue executing the loop so long as the condition is true.

Is
condition
true?

Yes

Process
Steps

(a) Flowchart for a loop

DO WHILE Condition is true

Process step(s)

Loop

a) Pseudo code for a loop


Example:
Problem: Calculate the report the grade-point average for a class
Input: Student grades
Processing: Find the sum of grades. Count the number of students; calculate
average grade = sum of grades/Number of grades

Output: Average grade

A flowchart should usually be traced. To trace a flowchart, we begin with the start
symbol and proceed from symbol to symbol until we reach the end symbol. Different
data should be used as input and the output checked. This process is known as desk
checking.
21
DESK CHECKING:

It should be mentioned that the reader should not expect to read an algorithm
as he reads a novel; the best way to learn an algorithm is to try it out.

Let us work algorithm E. Suppose, we are given m = 119 and n = 544.


Dividing m by n, the quotient is 0 and remainder 119.

Thus r ← 119, we proceed to step E2, and since r ≠ 0, no action occurs.

In step E3 we set m ← 544, n ← 119; if m < n originally, the quotient in step


E1 will always be zero and the algorithm will always proceed to interchange
m and n.

We could add a new step.

“E0 [Ensure m > n]. If m < n, exchange m ↔ n”.

Back to step E1, we find that 544/199 = 468/119, so r ← 68.

Again E2 is inapplicable, and we set m ← 199, n ← 68.

The next round sets n ← 51 and ultimately m← 68, n ← 51.

Next, r ← 17, and m ← 51, n ← 17.

Finally, divide 51 by 17, r ← 0, so at step E2 the algorithm terminates.

PSEUDO-CODE:

Pseudo-code is an intermediate language used for expressing algorithms; it does not have
rigid rules and permits us to focus on the problem the algorithm is designed to execute.

VARIABLE:

A word (symbol) is used to identify different things e,g, we are identified by a name. A name
can be attached to a value or number. When the value attached to a variable name does not
change; the name is called a symbolic constant. When the value attached ro a name can
change; it is called a variable name

Consider the following

A = 50

22
B = 20

Y=A+B

A, B and Y are variables. The braces {,} specify the beginning and end of the pseudo-code.

The three lines

A = 50

B = 20

Y=A+B

Are program statements. The statements specify the actions to be taken by the computer.
When the program is run, the statements are executed in order. The three statements are
assignment statements. An assignment statement acts to change the value of a variable. The
assignment operator is the “=” sign. The variable name on the left side of the symbol is the
variable whose value is to be replaced. The right side of the “=” is an expression that
determines the new value the variable is to assume. For example, when writing, Y = A + B,
we mean replacing the current value of Y with the current value of A + the current value of
B. Thus, after the three statements are executed, A will be equal to 50, B to 20 and Y to 70.

As a further example, we can increase, decrease or replace the current value of Y by adding
to or subtracting from it. Consider the following:

Y = 30

A = 40

Y=Y+A

After these statements are executed, Y will have the value of 70.

A further example is

Y = 20

Z = 50

W=Y+Z

M = W – 30

After these statements are run, W will have the value of 70 and M will have te value of 40.

23
Visually

Y Z W M

Step 1 20 ? ? ?

Step 2 20 50 ? ?

Step 3 20 50 70 ?

Step 4 20 50 70 40

In our pseudo-code, the addition symbol is the familiar “+” sign, the subtraction symbol is the
usual “-“ sign, multiplication is indicated by asterisk. Thus A * B means multiply A by B.
Therefore, the program statements:

A = 20

B = 30

C=A*B

Gives the value of 500 for C.

ORDER OF EXECUTION;

The order of actions of the statements is important:

m=n

n=r

is different from

n=r

m=n

The latter would imply that the previous value of n is lost before it can be used to set m; the
later sequence is equivalent to

n=r

m=r

To exchange values of two variables we can write

24
t=m

m=n

n=t

In summary, “m = n” means that the value of variable m is to be replaced by the current value
of variable n. Also, variable = formula means the formula is computed using the present
value of any variables appearing within it, and the result replaces the previous value at the
left of the “=”

Pseudo-code is a notation for expressing algorithms, devoid of strict rules required by


programming language syntax. The following constructs are the major English like
constructs:

1. Assignment Statement:

Variable = expression

This statement assigns the value of an expression into a variable.


Variable is the name that is attached to a value. A variable can be visualized as a
bucket with a label attached to it. The value of the variable is what is contained within
the bucket. An expression is the combination of variables, constants and arithmetic
operations such as (+,-,/,*)

Examples of expressions include ut + ½ gt2

An assignment statement replaces the contents of variable with the value of an


expression
Examples of assignment statements include:

totalAmount = savingsAccount + CurrentAccount


rectangleArea = length * width

2. Decision:
The decision statement selects one if two alternatives based on a condition. It has the
form:

If (condition) then
statements

if (condition) then

25
statements
else
statements
condition is a question that is evaluates to either yes or no.

3. Repetition(Looping)

Input

4. Output

PROGRAM DEVELOPMENT CYCLE

Program Planning

Before a program is written, there should be a plan. The recipe or plan reduces the
number of mistakes. Many programmers plan their program using a sequence of steps
referred to as the program development cycle. These are given below;

1. Analyze: Define the Problem


Be sure you understand what the program should do, that is what the output should
be. Have a clear idea of what data (or input) are given and the relationship between
the input and the desired output.
2. Design: Plan the Solution to the Problem
Find a logical sequence of precise steps that solve the problem. Such a sequence of
steps is called algorithm
3. Translate the Algorithm into a Programming Language
Coding is the technical word for writing a program. During thin stage, the algorithm is
translated into a programming language.
4. Test and Debug: Locate and Remove any Errors in the Program
Testing is the process of finding any errors in a program and debugging is the process
of correcting errors found during the testing process. (An error in a program is called
a ‘Big’)
5. Complete the Documentation: Organize all the Material that Describes the
Program
Documentation is intended to allow another person or the programmer at a later date,
to understand program. Internal documentation consists of statements in the program
that are not executed, but point out the purposes of various parts of the program.
Documentation also consists of a detailed description of what the program does and
how to use the program. For commercial programs documentation includes an
institution material. Other types of documentation are the flowchart, pseudo code and
top-down chart.

26
EXAMPLE 1(UI- CSC 142, 1982 Examinations)

(a) Define the terms algorithm and procedure? (4 marks)

(b) Algorithms can be formulated using the rules of sequencing, repetition and
choice, explain the underlined items using appropriate diagrams

SOLUTION:
EXERCISE 1:

Write an algorithm and draw a flowchart to find the average of a set of numbers:-

read number of numbers, N


for i = 1 to N
(read next number) input xi
(Accumulate numbers) totalNumbers = totalNumbers + Xi
(read next number) next i

27
Flowchart for to find average: of a set of N numbers:

Input N

I= 1

Input xi

totalNumbers =
totalNumbers + Xi

I= I+1

I <= N

Average =
totalNumbers/N

Print average

EXERCISE 2:

Write an algorithm and draw a flowchart to find the standard deviation of a set of
numbers; use the algorithm in example 1 as a sub-algorithm.

EXAMPLE 3: (CSC 142: Programming and Algorithms- 1982. CSC Department):

An algorithm is normally constructed from known sub-algorithms and primitive


operations. To demonstrate this fact, give the algorithm used for multiplying two
positive integers, using as primitive operations only the following:

(i) add (ii) Multiply and divide by 2 (iii) Ability to test if a number is odd or
even.

28
You may wish to use the fact that M/2 x 2N = M x N (12 marks)

You may test the correctness of your algorithm by applying it to the product of 6 x
17 (8 marks)

29
NETWORKING AND INTERNET

The need to share information and resources among different computers has lead to
linked computer systems, called network in which computes are connected so that data can be
transferred from machine to machine. In these networks, computer users can exchange
messages and share resources – such as printing capabilities, software packages and data
storage facilities that are scattered throughout the system.
The underlying software required to support such application has grown from simple
utility packages into an expanding system of network software.

Network Classification
A computer network is often classified as Local Area Network (LAN), a Metropolitan
Area Network (MAN) and a Wide Area Network (WAN).

LAN: A LAN normally consists of a collection of computers in a single building or building


complex. For example, the computers on a university campus or those in an office building

A MAN: This is a network of intermediate size such as one spanning a local community.

A WAN: A WAN links machine over a greater distance such as neighbouring cities or on
opposite sides of the world.

Types of Wireless Networks

1. Bluetooth: Bluetooth is a short range wireless technology that is designed to make its
own connections between electronic devices. Bluetooth networks form automatically
when two or more Bluetooth devices come within range of each other. A Bluetooth
network is also called a Piconet.
Bluetooth connectivity replaces the short cables that would otherwise hold on to a mouse,
keyboard, or printer to a computer or in other words, wireless mouse, keyboard and
printer are facilitated by Bluetooth.
To form a network, a Bluetooth device can search for other Bluetooth devices within
range. When another Bluetooth device is detected, it typically broadcast what it is. Before
data is exchanged the Bluetooth devices have to exchange pass keys or (PINS). Once the
pass keys have been exchanged, the two Bluetooth devices form a trusted pair. Future
communications between these devices do not require the pass key to be re-entered.
2. WI-FI: This is the other major wireless technology. WI-FI refers to a set of wireless
technologies defined by the professional body (IEEE 802) standard.

Network Hardware
1. Network Interface Card (NIC) – Network circuiting is required to connect computers;
these network circuiting on a special connection to the computer called the Network Card
or may be built into the device such as the printer, or computer.

30
2. Network Device: A network device or network appliance is any electronic device that
broadcasts network data, boost signals or routes data to its destination. Network devices
includes tubs, switches, routers, gateways, bridges and repeaters.

Types of Compute Network

1. Client Servers:
A server is a computer on a network which renders services to other computer(s) called
“clients” which requests for services. This gives rise to the client/server network. Usually
the server has a higher processor, larger storage and larger memory than the client.
2. Peer-to-Peer Network:
Rather than the workload concentrated on one computer as in the client server in peer-to-
peer mode, workstations share the responsibility for processing, storage, printing and
communication.

Network Topology
Network Topology refers to the arrangement of computers in a network. Network topology
has a remarkable effect in network performance. The major types of network topology are:
Star, Ring, Bus and Mesh.

Advantages of Computer Network


1. Networks enable people to work together i.e. collaborate using groupware and other
specialized network application software.
2. Sharing network software reduces the attendant costs. Network software is software
which is available to all users of the network.
3. Sharing data on the LAN increases productivity.
4. Sharing networked hardware reduces costs.

31
THE INTERNET

The Internet, as already explained is a global network of computer network in more


specific terms an internetwork. In fact, the word Internet is a combination of two words inter
and network.

The Internet evolved from the original United States Defense Advanced Research
Project Agency sponsored project in 1967, which connected for university sites to a network
sponsored by National Science Foundation (NSF) and has evolved today to a network made
up of billions of computer. (Denning, CACM 9)

A major aspect of an Internet is its ability to transfer information amongst computers


of different types and running different operating systems; and through different
communication media such as cables (wired), electromagnetic waves (wireless), etc.

Protocols of the Internets

Communication protocols refer to the procedures, the meaning of messages sent


(semantics) and the form of messages sent (syntax). Protocols are what facilitates the
communication of data. For the internet, the major protocols are

1. Internet Protocols (IP)


2. Transmission Control Protocol (TCP)
3. Hypertext Transfer Protocol (HTTP)

Internet Protocol (IP)

To facilitate data communication, the Internets needs to identify computers using an address
attached to messages. The IP deals with this aspect.

Transmission Control Protocol (TCP)

Transmission Control protocol are the procedures which ensure reliable end to end delivery
of messages also called segments.

Hypertext Transfer Protocol (HTTP)

Hypertext Transfer Protocol ensures end to end delivery of a document from one computer to
the other.

These three protocols are the software aspects of the Internet which ensures that
messages are reliably sent from one computer to another. In summary, the internet is enabled
by the TCP/IP and HTTP communications protocols

32
.APPLICATION ON THE INTERNET

The internet is a communication infrastructure that runs several applications including


but not limited to the following:

1. World Wide Web (WWW): The World Wide Web (WWW) consists of documents
and links embedded within those documents to other documents. Documents on the
Web are identified by an address called the User Resource Locator (URL).
Documents on the web are accessed through a software called a browser. A Browser
interprets and displays these documents. The web documents are referred to as “Web
Pages”. Web pages are created using a language called the Hypertext Markup
Language (HTML). The use of the web has evolved from simply being public
relations medium to one in which the complete business processes can be modeled.
2. Email: The email is used by people for sending and receiving mails, using the
internet infrastructure. The authority of composing, sending and receiving mails is
handled by a program called the email client.
3. Instant Messaging (IM): Instant messaging uses client application to have real time
messaging. Examples are; AIM, Windows Live Messenger, Yahoo Messenger, etc.
4. Search Engine: The search engine provides a list of documents stored on other
computers converted to the web. Examples are Google, Yahoo, etc.
5. Voice Communication (Internet Telephone): This enables users to transmit and
reduce Vone conversation e.g. Skype, Windows Live Messenger, etc.

33
34
NUMBER SYSTEMS
INTRODUCTION

A thorough knowledge of number systems and conversion between them is important


in the study of computer architecture because

1) Computers were initially designed to crunch numbers using addition, subtraction


multiplication and division and therefore numbers need to be represented in the
computer before manipulation is possible.
2) The computer is more suited to handling signals represented as binary numbers whist
humans handle numbers in base 10; therefore a proper knowledge of conversion
between number bases is important.

It should be reiterated that numbers are a notation for representing how many things
there are. The symbols 1, 2, 3. 4, . . . 9, were invented in India to represent the
conceptual notation of one, two or three thing etc.

NUMBER BASES AND DECIMAL EXPANSION OF A NUMBER:

In this section, we present a number such as a nan-2 . . . ao as an amalgamation of


groupings, limited by a base. These groupings are necessitated by the fact that to
count an extra symbol (e.g. 0, 1, 2, 3 etc) cannot be created for every extra thing we
wish to count, the symbols are repeated using an ingenious system called the place
value system. The number of things which are grouped before a repetition is called
the number base. Therefore the conceptual idea of how many can be represented in
different number bases. The common number bases are:

Grouping of Two Binary


Grouping of Three Ternary
Grouping of Eight Octal
Grouping of Ten Decimal
Grouping of Sixteen Hexadecimal

For example, given the following things which need be counted,

35
In base 10,

36
=1 =2 =3

=5
=4

=6 =7

=8
=9

Figure 2.1

Counting the next person after this results in a group of ten things; which is
represented by putting a 1 to the left of 0 i.e 10 rather than creating a new symbol for
ten. Therefore, 10 represents a group of ten things

In general, a number represented as a nan-1 . . . a0 in base 10 can be interpreted in words


as
an groups of 10 groups of . . . 10n-1 things
plus

37
an-2 groups of 10 groups of . . . 10n-2 things in terms of groupings

.
.
an things
The common literature simply gives the expansion of a number as as
an10n-1 + an-110n-2 + . . . + a0
However, we have taken time to explain the logic of this representation.

Example 1:
Give the decimal expansion of 851:
851 = 8 x 103-1 + 5 x 103-2 + 1 x 103-3
= 8 x 102 + 5 x 101 + 100
= 8 x 100 + 5 x 10 + 100
= 800 x 50 + 1

Example 2:
Give the decimal expansion of 5672:
851 = 5 x 104-1 + 6 x 104-2 + 7 x 104-3 + 2
= 5 x 103 + 6 x 102 + 7 x 104-3 + 2 x 100
= 5 x 1000 + 6 x 100+ 7 x 10 + 2 x 1
= 5000 + 600 + 70 + 1

This notation is commonly referred to as the place value system, because a symbol
value is derived from its position in the number and also an fixed(absolute) symbol.

Example 3:
What is the value of 5 in 853.
Solution:
The value of 5 is 50 in this number

Example 4:
What is the value of 5 in 524

Solution:
The number 5 has a value of 5 hundred in the example above.

Example 5:
What is the value of 5 in 5824

Solution:
The number 5 has a value of Five Thousand in 5824
Equation (i) above can be generalized as follows

38
anbn-1 + an-1bn-2 + . . . + a0
where b stands for the base of the number system

Example 6:
Give the binary expansion of 1001012
1001012 = 1 x 25 + 0 x 24 + 0 x 23 + 1 x 22 + 0 x 21 + 1 x 20
Here, b(the base) = 2
a2 = 1; a1 = 2; a0 = 1
Example 7:
Give the base 5 expansion of 52485
In base 5,
52485 = 5 x 53 + 2 x 52 + 4 x 51 + 8 x 50
Here, b(the base) = 5
a3 = 5; a2 = 2; a1 = 0; a0 = 8

Example 8:
Give the base 16 expansion of 5A3B16
In base 16,
5A3B16 = 5 x 163 + A x 162 + 3 x 161 + B x 160
Here, b(the base) = 16
a3 = 5; a2 = A; a1 = 3; a0 = B

This example can be generalized for fractional number as follows. The fractional
numbers can be represented as follows:
an-1bn-1 + an-2bn-2 + . . . + a0.a—1b-1 + a—2b-2 + a—3b-3 + . , .

Example 9:
Give the decimal expansion of 5.875.
5.875 = 5 x 100 + 8 x 10-1 + 7 x 10-2 + 5 x 10-3

Example 10:
Give the decimal representation of 1.0110.11012

Solution:
10110.11012 = 1 x 24 + 0 x 23 + 1 x 22 + 1 x 21 + 0 x 20 + 1 x 2-1 + 1 x 2-2 + 0 x 2-3 + 1
x 2-4
The purpose of the foregoing discussion is to illustrate that a number such as 583 is a
notation for denoting a hierarchy of groupings starting from the right; each grouping
is represented by symbols. For example the groupings 583 above can be read as
“Five Groups of 8 Groups each of three units. In decimal, the first level of groupings
are called units, the next level of grouping are called Tens and the Third are the
Hundreds etc. The symbol 0 either represents nothing or a group of Ten. I am
39
currently unaware of any naming of group levels in other number bases such as base
2 etc as there are in 100.

Our presentation of a number s an amalgamation of groupings diverges from the


traditional manner of presentation of numbers and emphasizes the logical content.

2.2 CONVERSION BETWEEN NUMBER BASES

From the discussion given above, it is easily seen that conversion between number
bases is simply equivalent to grouping and regrouping.

2.1.1 CONVERSION TO BASE 10 FROM ANY NUMBER BASE

We can convert to base 10 from a number base x, simply by using the expansion of
the form
an-110n-1 + an-110n-2 + . . . + a0
where n is the number of digits and b is the number base

In practice, the place value of each digit is known or can be computed expeditiously.
For the least significant digit (LSD), which is the rightmost digit of the number, the
place value is given by b0, for the next most rightmost significant digit (the value to its
immediate left), the place value is given by b 1, this pattern continues successively
increasing the power of the base as we move to the left.

Example 11:

Convert 1012 to base 10

Solution:
1012 = 1 x 22 + 0 x 21 + 1 x 20
=4+0+1=5

Example 12:
Convert 10012 to base 10
Solution:
10012 = 1 x 23 + 0 x 22 + 0 x 21 + 0 x 20
=8+1=9

CONVERSION TO ANY NUMBER BASE FROM BASE 10

Conversion to any number base from base 10 to base b is carried out by repeated
division of the number in base 10 by the base b we wish to convert to. The remainder

40
after each division indicates the digits of the number in the new base; read in a last in
first out (LIFO) order i.e the last remainder obtained is the MOST SIGNIFICANT
DIGIT (MSD) ( i.e the leftmost number or the digit with the highest value) of the new
number; whilst the first remainder is the LEAST SIGNIFICANT DIGIT (LSD) ie the
rightmost number or the digit with the least value) of the number.

EXAMPLE 14

Convert 12510 to base 2

SOLUTION:

125 / 2 = 62 remainder 1
62/2 = 31 remainder 0
31 / 2 = 15 remainder 1
15/2 = 7 remainder 1
7/2 = 3 reminder 1
3/2 = 1 remainder 1

The remainders are now written in the last in first out method is 11111012
In contemporary literature, the above division is presented as shown below and should
be used for examination purposes.

2 125 62 rem 1
2 62 31 rem 0
2 31 15 rem 1
2 15 7 rem 1
2 7 3 rem 1
2 3 1 rem 1
2 1 0 rem 1

=> 12510 = 11111012

EXAMPLE 15
Convert 12510 to base 5

SOLUTION:
5 125 25 rem 0
2 25 5 rem 0
2 5 5 rem 1
2 1 0 rem 1

=> 12510 = 10005


41
FRACTIONAL NUMBERS

To convert a fractional number in decimal form to base x we subtract the highest


negative powers of the base which can be removed from the number, successively.

EXAMPLE 15

Convert 0.87510 to base 2

SOLUTION:

The powers of the negative numbers of 2 are:- 2 -1 = 0.5; 2-2 = 0.25; etc. These are
successively subtracted from 0.875 as shown

0.875 – 2-1 = 0.875 – 0.5 = 0.375


0.375 – 2-2 = 0.375 – 0.25 = 0.125
0.125 – 2-3 = 0.125 – 0.125 = 0

Therefore, 0.875 decimal is represented by 0.1112

EXAMPLE 17:

Convert 0.62510 to base 2

SOLUTION:

The powers of the negative numbers of 2 are:- 2 -1 = 0.5; 2-2 = 0.25; etc. These are
successively subtracted from 0.625 as shown

0.625 – 2-1 = 0.625 – 0.5 = 0.125


0.125 – 2-3 = 0.125 – 0.125 = 0

Therefore, 0.62510 decimal is represented by 0.101

ALTERNATIVE METHOD:

An alternative method multiples the fractional part successively by 2. After each


multiplication, the whole number part of the fraction is either 0 or 1. This process is
continued until, the fractional part repeats or is 0. The equivalent binary number is
then read from the first multiplication to the last.

42
EXAMPLE

0.6875
2
1.3750
x2
0.7500
x 2
1.5000
x2
1.0000
0.687510 = 0.10112

2.3 CONVERSION OF MIXED NUMBERS

A number is referred to as a mixed number if it contains both an whole number part


and a fractional part e.g 1.587, 8.976 etc. To convert mixed numbers we convert the
whole number part and the fractional part separately.

EXAMPLE 18:

Convert 8.625 to base 2

SOLUTION:

2 8 4 rem 0
2 4 2 rem 0
2 5 1 rem 0
2 1 0 rem 1

The binary equivalent of the integer part is 1000 2. The fractional part is the same as
example 2 above i.e. 0.1012.
Therefore, 8.625 = 1000.1012

Example 13
Convert 11.0112 to base 10
Solution:
11.0112 = 1 x 21 + 1 x 20 + 0 x 2-1 + 0 x 2-2 + 1 x 2-3
= 2 + 1 + 0.5 + 0.25 + 0.125
= 3.875

43
EXAMPLE 19 (LASU ASSEMBLY LANGUAGE 2007/2008- EXTERNAL
SYSTEM EXAMINATIONS):

Convert

(i) 25 (ii) 125 (iii) 0.85

SOLUTION:

Applying the repeated division method explained earlier, we have


(i)
25/ 2 = 12 remainder 1
12/2 = 6 remainder 0
6/2 = 3 remainder 0
3/2 = 0 remainder 1
1/2 = 0 remainder 1

2 25 12 rem 1
2 12 6 rem 0
2 6 3 rem 0
2 3 1 rem 1
2 1 0 rem 1

The binary equivalent of 2510 = 110012.

(ii)

5 125 62 rem 1
2 62 31 rem 1
2 31 15 rem 0
2 15 7 rem 1
2 7 3 rem 1
2 3 1 rem 1
2 1 0 rem 1
12510 = 11110112

(iii)

0.85 – 2-1 = 0.85 – 0.5 = 0.35


0.35 – 2-2 = 0.35 – 0.25 = 0.10
0.10 – 2-4 = 0.85 – 0.0625 = 0.0375
0.0375 – 2-5 = 0.0375 – = 0.031275= 0.001

44
Therefore 0.85 ≈ 0.110112

2.4 CONVERSION FROM BASE X TO BASE Y

To convert from an arbitrary base X say base 5 to another base say base y, we need to
first covert to base 10 (using the method of expansion and addition) and then convert
to the desired base by repeated division.

EXAMPLE 20:
Convert 23445 to base 3
Solution:

Converting to base 10
2 x 53 + 3 x 52 + 4 x 5 + 4 x 50
= 2 x 125 + 3 x 25 + 20 + 4
= 34910
Converting To base 3, by repeated division, we have

3 349 116 rem 1


3 116 38 rem 2
3 38 12 rem 2
3 12 4 rem 0
3 4 1 rem 1
3 1 0 rem 1

Therefore, 34910 is equivalent to 1102213

2.5 CONVERSION FROM BINARY TO HEXADECIMAL OR OCTAL

It is particularly convenient to convert from binary to octal or hexadecimal and vice


versa.

To understand these conversions we need to realize that each octal digit has a binary
equivalent as follows:-

08 = 0002; 18 = 0012; 28 = 0102; 38 = 0112; 48 = 1002; 58 = 1012; 68 = 1102; 78 = 1112

Recall that the highest number that can exist in the world of octal is 7. Each binary
equivalent of the number is the binary conversion of the decimal digit.

The binary equivalents of the hexadecimal digits are also given as follows:

45
016 = 00002; 116 = 00012; 216 = 00102; 316 = 00112; 416 = 01002; 516 = 01012; 616 = 01102;
716 = 01112; 816 = 10002; 916 = 10012; A16 = 10102; B16 = 10112; C16 = 11002; D16 =
11012; E16 = 11102; F16 = 11112;

Now, to convert from octal to hexadecimal and vice versa, we simply replace the
relevant binary equivalent starting from the right and padding the leftmost bits with
zero to make up 4 binary digits (hexadecimal) or 3 binary digits (binary) as the case
may be

EXAMPLE 21:
Convert A3216 to binary

Solution
From the table above,
A= 10102; 3 = 00112; 2 = 00102
=> A3216 = 1010 0011 00102

EXAMPLE 22:
Convert 01011000100 to base 8.

Solution:
Start aggregating in groups of 8 bits from the right side i.e.
010 011 000 100
2 3 0 4

Note that an extra zero is added to the left side of the number to make it 3 digits.

EXAMPLE 23(LASU 2008, ASSEMBLY LANGUAGE No. 9):

i) Convert 24710 to hexadecimal

SOLUTION:

Divide 24710 repeatedly b 16 as follows:

SOLUTION:

16 247 15 rem 7
16 15 0 rem 15
=> 24710 = F716

ii) 3410 to binary

46
SOLUTION:

2 34 17 rem 0
2 17 8 rem 1
2 8 4 rem 0
2 4 2 rem 0
2 2 1 rem 0
2 1 0 rem 1

3410 = 1000102

iii) 110010012 to hexadecimal


SOLUTION:
Aggregate the numbers from right to left; padding if necessary with 0
110010012 = 1100 1001
Replace each group by the hexadecimal equivalent
i.e. C 916

2.6 ARITHMENTIC OPERATIONS IN DIFFERENT NUMBER BASES:

Arithmetic operations- addition, subtraction, multiplication and division- can be


performed irrespective of the base in which the numbers are represented. For instance,
the computer performs its arithmetic in base 2

2.6.1 ARITHMENTIC ADDITION


Arithmetic addition is carried out by counting from the augend (the number to be
added to), with the addend (the number to be added); the rule in arithmetic addition is
that once the maximum digit of the grouping is reached a carry (1) is generated and
added to the left i.e the maximum digit in a number system with base n is n-1. For
example, in base 5 the maximum digit is 4 5; thereafter the counting is started again, so
45 + 35 = 125 because after 4, we have 105, 115, 125 . . .

EXAMPLE
Add the following numbers in binary (i) 101 2 + 1102 (ii) 11112 + 101002 (iii) 10.012
+ 101.112

SOLUTION:
In binary,

1012 11112 10.012


+1102 101002 101.112
10112 1000112 1000.002

47
In each of these three numbers, the addition is from the right hand side (RHS) to the
left hand side (LHS). After 1 is counted the next number is a carry plus 0. For
example adding 0 to 1 is 1; adding 1 to 0 is 1 and adding 1 to 1 is 10; the one being a
carry.

2.6..2 ARITHMETIC SUBTRACTION

The subtraction of numbers is counting downwards the number to be subtracted (the


subtrahend) from the number to be subtracted from (the Minuend) and recognizing
that the maximum digit for base n is n-1. Therefore , 4 -3 is 1.

Now, situations arise where the digit to be subtracted (subtrahend) is more than the
digit to be subtracted from(minuend) e.g. 3-4. In this case a negative number results.
When the digit of the minuend is less than the subtrahend, a borrow can be made
from the next most significant digit e.g

Most Significant Digit((MSD) ->5 8 7 2 -> Least Significant Digit (LSD)

It should be noted from the above that the significance of the digits increases from left
to right.

Example 23:

2 4 35
- 1 0 45
1 3 45

Explanation:

The digit 3 (the least significant digit) of the minuend is less than 4, the least
significant digit of the subtrahend; therefore a carry is taken from the next most
significant digit of the minuend i.e. 4. It should be noted that this carry is equivalent
to 135 not 1310. The next consideration therefore is to determine how many digits one
needs to count from 45 to 135 i.e 105, 115, 125, 135; therefore the difference is 5 5. The
carry from 4 is 35. Continuing in this manner, the answer is 1345

Example 24:

i) 1001 ii) 10000


- 10 1 - 11
1 0 02 1 1 0 12

48
iii) 1 1 0.0 1
- 1 0 0.1 0
1.1 1

For decimal numbers, the numbers must be aligned on the decimal point before the
subtraction.

2.6.3 MULTIPLICATION:

Multiplication the gradual addition of many numbers is best done using a


multiplication table; that of base 10 being learnt from childhood can be easily applied.
However, we frequently need to perform multiplication on numbers in other bases
which we are not familiar with. A way out is to perform each stage of the
multiplication in base 10 and to eventually convert the result to the desired base, for
instance

Example 24:

2 3 79
x 1 89
2132
237
4 4 0 29

This is performed by using

7 x 8 = 5610  629
3 x 8 = 2410  269 + 69 = 339
2 x 8 = 1810  209 + 3 (Carry) = 239

Example 25:

1100
1010
0000

1100

0000

1100

1 1 1 0 0 02

Example 26:
49
1100110
1000
1100110000

Example 27:

1 .0 1
1 0. 1
101
1010
11.001

2.6.4 DIVISION:

In division, there are two numbers, the number to be divided (Dividend) , and the
number that divides (the divisor), the result of the division (the quotient), and a
possible remnant (remainder).after the division.

In dividing, we find how many times the divisor can be removed from the dividend
using as many digits as possible, starting from the most significant digit.. This (i.e. the
number of times) is then multiplied by the divisor to obtain a value which is then
subtracted from the digits selected to obtain a remainder. Additional digits are
selected from the dividend and the procedure repeated until the end of the dividend is
reached.

Example 28:

5810 - 410

This is normally put in the form


____________
4 | 58

Step 1:

Find out how many times the divisor can be removed from the dividend using as
many digits as possible, starting from the most significant digit (MSD)

Here, the most significant digit is 5, since 4 goes into 5, we need only one digit, if it
did not divide 5, we might have used 58.

4 divides 5 once; we write this on top as shown below:

50
___1________
4| 58

Step 2:

Multiply 1 by the divisor and subtract from the digits selected to obtain a remainder

i.e.

___1________
4| 58
4________
1

Step 3:

Additional digits are obtained from the dividend i.e. 8

___1________
4| 58
4________
18

And the procedure is repeated until there are no more digits to remove from the
dividend.

___1________
4| 58
4________
18
__16_____
2

The result of the division is 14 2/4

Example 29

Perform the following multiplication and divisions in the binary number system:

a) 24 x 12 b) 31 x 14

51
Solution:

a) Conversion to binary

2 | 24 2 | 12
2 | 12 rem 0 2 | 6 rem 0
2 | 6 rem 0 2 | 3 rem 0
2 | 3 rem 0 2 | 1 rem 1
2 | 1 rem 1 | 0 rem 1
2 | 0 rem 1

2410 = 110002 1210 = 11002

2410 x 1210 = 11000


1100
00000
00000
11000
11000
1110000

Example 30:
31 x 12 in binary

Solution:

2 | 31 2 | 14
2 | 15 rem 1 2 | 7 rem 0
2 | 7 rem 1 2 | 3 rem 1
2 | 3 rem 1 2 | 1 rem 1
2 | 1 rem 1 | 0 rem 1
2 | 0 rem 1

31 = 111112 14 = 11102

11111
1110
00000
11111
11111
11111____
1101100102

52
2.7 RADIX AND RADIX 1’1s COMPLEMENT

Negative numbers can be represented in notations called radix complement. Radix


refers to the base of a number system. Therefore, we have 10’s complement for base
10 numbers, 9’s complement –equivalent of the radix -1 complement for base 10.

Advantage:
The advantage of this complement is that they permit us to use addition to perform
subtraction. For the computer addition circuits are easier to construct than subtraction
circuits.

2.7.1 CONVERSION OF NEGATIVE NUMBERS TO RADIX -1 COMPLEMENT

To convert a negative number to its complement, we simply subtract each digit of the
number from the radix (base) – 1.

For example,

9’s complement of 238 = 761 which is obtained by substituting each digit i.e. 8, 3 and
2 from 9.
3’s complement of 2314 = 2134
Subtracting 2, 3, and 1 and 1 from 4
1’s complement of 1012 is 1012

The complement in base two is particularly easy because it can be obtained simply by
flipping the bits.

Radix Complement
The radix complement can be obtained by forming the radix – 1 complement and
adding 1 to the result.
For example,
10’s complement of 238 = 761 + 1 = 762
4’s complement of 2314 = 2134 + 1 = 2144
2’s Complement of 1012 = 0102 + 1 = 0112

2.7.2 SUBTRACTION USING RADIX COMPLEMENT:

As explained earlier a major motivation for the complement system is to permit


subtraction to be done using addition. To subtract, we convert the subtrahend i.e. the
number to be subtracted to two’s complement and add to the minuend. If a carry is
generated after the addition it is simply discarded and the result is the answer of the
subtraction (with the negative sign prefixed i.e.

53
Example 31
10’s Complement
Minuend 76 76
Subtraend -25 75
51 151

When the 1 is discarded it is seen that it’s the result with the negative sign prefixed to
the number.
However, if no carry is generated the result must be converted and a negative sign
prefixed to it.

Example 32:
9’s Complement
49 Minuend 49
-62 Subtranend 38
-1310 8710

Here, there is no carry and 87 is converted to its 10’its 10’s complement i.e. 12 + 1 =
13 and the sign is prefixed i.e. -13

2.7.3 SUBTRACTION USING RADIX – 1 COMPLEMENT

For subtraction in radix -1 complement the same procedure is used as in the radix
complement. However, the carry is carried around rather than being discarded when a
carry is generated e.g. in 9’s complement

Example 33:

NORMAL SUBTRACTION 9’S COMPLEMENT

89 89 89
23 -23 = 76
66 | 165
- _1
66

However, if no carry is generated, the result is converted to 9’s complement and a


negative sign prefixed

Example 34:

NORMAL SUBTRACTION 9’S COMPLEMENT

54
15 15 15
37 -37 = 62
-22 | 77

There is no carry in this case so the difference is negative 9’s complement which is -
22.

However, if no carry is generated, the result is converted to 9’s complement and a


negative sign prefixed

Example 35:

Subtract 12510 – 4510, using 1’s complement arithmetic.

Solution:

12510 to binary = 2 | 125


2 | 62 rem 1
2 | 31 rem 0
2 | 15 rem 1
2 | 7 rem 1
2 | 3 rem 1
2 | 1 rem 1
| 0 rem 1

=> 12510 = 11111012

4510 to binary = 2| 45
2| 22 rem 1
2| 11 rem 0
2| 5 rem 1
2| 2 rem 1
2| 1 rem 0
2| 0 rem 1

4510 = 1011012

111111012 11111012
-10110112 10100102
101000002 11001111
------1
1010000

55
EXCERCISES:

1. Convert the following binary numbers to their decimal equivalents:


a) 10000000 b) 00010000 c) 00110011 d) 01100100 e) 00011111 f) 11111111

2. Convert the following decimal numbers to their binary equivalents


a) 23 b) 39 c) 55 d) 48

3. 20410 = _______________2

4. Convert the following binary numbers to their hexadecimal equivalents:


a) 1009 b) 1100 c) 1101 d) 1111 e) f) 01111110 g) 00010101 h)
11111011

56
Questions.
Explain the following.
1. General purpose Computer and Dedicated Computer
2. Microcomputer, Microprocessor, Minicomputer and Mainframe Computer?
3. What is an IC?
4. Differentiate between a microcomputer and microprocessor ?

57

You might also like