Introduction to Computers Lecture notes
Introduction to Computers Lecture notes
INTRODUCTION
What is a computer?
A Computer is an electronic device that can perform activities that involve
Mathematical, Logical and graphical manipulations.
It performs the following three operations in sequence.
1. It receives data & instructions from the input device.
2. Processes the data as per instructions.
3. Provides the result (output) in a desired form.
Advantages of computers
1. High speed: Computers have the ability to perform routine tasks at a greater
speed than human beings.
2. Accuracy: Computers are used to perform tasks in a way that ensures
accuracy.
3. Storage: Computers can store large amount of information.
1
Generations of computers:
Generation Component used
First Generation Vacuum tubes
(1946-1954 )
Second Generation Transistors
(1955-1965)
Third Generation Integrated Circuits (IC)
(1968-1975 )
Fourth Generation Very Large Scale Integrated Circuits
( 1976-1980) (VLSIC)
Fifth Generation Ultra-Scale Integrated Circuits (ULSIC)
(1980 – till today ) Micro Processor (SILICON CHIP)
Anatomy of Computers
The computer system consists of three units:
1. Input device
2. Central Processing Unit (CPU)
3. Output device
2
Units and Their Functions
1. Input device: Reads information from input media and enters to the computer
in a coded form.
2. CPU
(a) Memory unit: Stores program and data
(b) Arithmetic Logic unit: Performs arithmetic and logical operations
(c) Control Unit: Interprets (translate from high level to low level) program
instructions and controls the input and output devices
(a) Memory Unit: It is also known as the primary storage or main memory. It
stores data, program instructions, internal results and final output temporarily
before it is sent to an appropriate output device.
(b) Arithmetic and Logical Unit (ALU): It is the unit where all Arithmetic
operations (addition, subtraction etc.) and logical operations (>, <, AND, OR etc.)
are performed. Logic operations include any operations that manipulate
Boolean values. Boolean values are either true or false. Intermediate generated
results in ALU are temporarily placed in memory until needed at later time. Data
may move from primary memory to ALU and back again to storage many times
before the process is finalized.
(c) Control Unit: It acts as a central nervous system and ensures that the
information is stored correctly and the program instructions are followed in
proper sequence as well as the data are selected from the memory as necessary.
It also coordinates all the input and output devices of a system.
Input Devices
Devices used to provide data and instructions to the computer are called Input
devices. Some important input devices are:
3
Key board, Mouse, Scanner, Web camera, Microphone, Barcode reader, Flash
Disk (?) etc.
Output devices
Any device that is capable of representing information on a computer is called
an Output device. Output devices receive information from the CPU and present
it to the user in the desired form.
Some important Output devices are: Monitor, Printer, Plotter, Projector,
Speakers, Headphone, etc.
Units of Memory
The computer stores a character in the storage cells with binary (0, 1)
mechanism. Thus the basic unit of memory is a bit (binary digit). A bit has a single
binary value, either 0 or 1.
Byte
A group of 8 bits is called byte. A byte is the smallest unit, which can represent
a data item or a character.
There are really 1024 bytes in a kilobyte. The reason for this is because
computers are based on the binary system. That means hard drives and memory
are measured in powers of 2. For example,
4
20 = 1
21 = 2
22 = 4
23 = 8
24 = 16
25 = 32
26 = 64
27 = 128
28 = 256
29 = 512
210 = 1024
Notice how 210 is 1024. Therefore, 210, or 1024 bytes compose one kilobyte.
Furthermore, 1024 kilobytes compose one megabyte, and 1024 megabytes
compose one gigabyte.
ex:
2GB=?KB
2GB=2*1024MB=2048MB
2048MB=2048*1024KB=2097152KB
ex:
500KB=?GB
500KB=500/1024MB= 0.4883MB
0.4883MB=0.4883/1024GB=0.0004768GB
5
Types of Memory
A computer memory is of two types
1. Primary Memory (Internal storage)
2. Secondary Memory (External storage)
Primary Memory
Primary memory is also called internal memory and is an important part of a
computer. It is the main area in a computer where the data is stored. This
memory can be quickly accessed by the CPU for reading or storing information.
Primary memory is further classified into two types:
Random Access Memory (RAM)
Read - Only Memory (ROM )
Secondary Memory
The primary memory which is faster (and hence expensive) is generally not
sufficient for large storage of data. As a result, additional memory, called the
“auxiliary” or “secondary memory” is used. It is also referred as “backup
storage” as it is used to store large volume of data on a permanent basis which
can be transferred to the primary memory. Some of the devices of secondary
storages are Floppy Disk, Hard Disk, CD-ROM, DVD and Flash drive.
1. Floppy Disk
It is also referred as “Diskette”. The disks are available in two sizes of 5.25 and
3.5 inches. Storage capacity of floppies are measured in kilobytes (KB) and
megabytes (MB).
6
2. Hard Disk
The hard disk drive is the main, and usually largest, data storage hardware
device in a computer. Can be internal or external. A hard drive can be used to
store any data, including pictures, music, videos, text documents, and any files
created or downloaded. Also, hard drives store files for the operating system
and software programs that run on the computer. Older hard drives had a
storage size of several hundred megabytes (MB) to several gigabytes (GB).
Newer hard drives have a storage size of several hundred gigabytes to several
terabytes (TB).
3. CD-ROM
CD-ROM stands for Compact Disk–Read Only Memory. Its main advantage is that
it is portable and can hold a large amount of data. To use a CD-ROM, a device
called CD drive is needed.
CD-ROMs have the following variations:
(i) CD-R (Compact disc Recordable): Data can be written onto it just once. The
stored data can be read. Data once written onto it cannot be erased.
(ii) CD-RW (Compact disc Rewritable): It is also called erasable CD. Data once
written onto it can be erased to write or record new information many times.
4. DVD
DVD stands for Digital Versatile Disc. It is similar to a CD-ROM, except that it can
store larger amounts of data.
One of the most common DVD's is the single-sided, single-layer disc, capable of
holding 4.7 GB.
The single-sided, double-layer disc is capable of holding between 8.5-8.7 GB.
The double-sided, single-layer disc is capable of holding 9.4 GB.
Although rare, the double-sided, double-layer disc is capable of holding up to
17.08 GB.
5. Flash Drive
It is a small, portable device that can be used to store, access and transfer data.
They are available in sizes ranging from 2 GB to 1 TB.
7
HARDWARE AND SOFTWARE
Hardware
The physical components of the computer are known as “Hardware”. It refers to
the objects that we can actually touch.
Ex: input and output devices, processors, circuits and the cables.
Software
Software is a program or set of instructions that causes the Hardware to function
in a desired way.
There are five categories of software. They are:
1. Operating System
2. Translators
3. Utility programs
4. Application programs
5. General purpose programs
2. Translators
Computers can understand instructions only when they are written in their own
language – the machine language . Therefore, a program written in any other
language should be translated into machine language. The software that
“translates” the instructions of different languages is known as translators .
There are two types of translators. They are compilers and Interpreters.
8
Programming Languages:
There are three types of programming languages.
b) Assembly Languages : It uses mnemonic codes rather than numeric codes (as
in machine languages). Mnemonic is an abbreviation for an operation. Ex. Add
or A is used as a symbol for addition, inc increase by one, BAL branch and link. It
requires translators to convert into machine language. Like machine language,
writing program in assembly language is also time consuming. These are also
machine dependent.
c) High Level Languages (HLL): These are referred as problem oriented languages
(POL). The high level languages are convenient for writing programs. Such
languages are considered high-level because they are closer to human
languages. These are referred as third generation languages.
3. Utility Programs
These are pre-written programs supplied by the manufacturer for maintaining
day to day activities of computer system.
Example: COPY, SORT, MAILING, virus scanning software, web browser, music
player
4. Application Programs:
These are user written programs to do a specific job which can be changed to
meet the individual needs. These programs are written in different languages
such as BASIC or C
9
i) Data Analysis
ii) Word Processing
iii) Spread Sheet
iv) Graphics and
v) Databases
Classification of Computers
Computers are classified according to the storage capacity, speed and the
purpose for which they are developed. These can be classified into three types:
1. Analog Computes
2. Digital Computers
3. Hybrid Computers
A majority of the computers that are in use are digital computers. The digital
computers are classified into
1) Special Purpose Computers and
2) General Purpose Computers
10
1. Special Purpose Computers: These are developed with a specific purpose.
Some of the areas where these computers are being used are – soil testing,
medical scanning, traffic signals, etc.,
Mini Computers: A minicomputer fills the space between the mainframe and
microcomputer, and is smaller than the former but larger than the latter.
Minicomputers are mainly used as small or mid-range servers operating
business and scientific applications.
11
CHAPTER 2
NUMBERING SYSTEMS and CONVERSION FROM ONE SYSTEM TO ANOTHER
Binary [ 2 ] .
Uses 2 symbols: the digits 0 and 1.
Some numbers in this system: (0)2, (000)2, (1010)2.
Decimal [ 10 ]
Uses 10 symbols: the digits 0, 1, 2, … ,9.
Some numbers in this system: (111)10, (0)10, (1010)10.
Octal [ 8 ]
Uses 8 symbols: the digits 0, 1, 2, 3, 4, 5, 6, 7.
Some numbers in this system: (111)8, (7)8, (1010)8.
Hexadecimal [ 16 ]
Uses 16 symbols: 0, 1, 2, …., 9, A, B, C, D, E, F.
Some numbers in this system: (111)16, (C)16, (1A10)16.
12
2. Octal to Decimal Conversion
Second step of the given method should be modified as
List the powers of eight from right to left.
13
=192 + 48 + 2 + 0.375+ 0.078125= (242.453125)10.
Other conversions:
1. Decimal to Binary Conversion
To convert a number in decimal to a number in binary we have to divide
the decimal number by 2 repeatedly, until the quotient of zero is
obtained. This method of repeated division by 2 is called the ‘double-
dabble’ method. The remainders are noted down for each of the division
steps. Then the column of the remainder is read in reverse order i.e., from
bottom to top order.
ex: Convert (26)10 into a binary number.
Devision Quotient Generated remainder
26/2 13 0
13/2 6 1
6/2 3 0
3/2 1 1
1/2 0 1 Result: (11010)2
14
ex: Convert (8023)10 into a binary number.
Devision Quotient Generated remainder
8023/2 4011 1
4011/2 2005 1
2005/2 1002 1
1002/2 501 0
501/2 250 1
250/2 125 0
125/2 62 1
62/2 31 0
31/2 15 1
15/2 7 1
7/2 3 1
3/2 1 1
1/2 0 1 Result: (1111101010111)2
15
ex: Convert (948)10 into a hexadecimal number.
Devision Quotient Generated remainder
948/16 59 4
59/16 3 11 note that this equal to B
3/16 0 3 Result: (3B4)16
16
6. Octal to Binary Conversion
Each octal digit is converted into a 3-bit-equivalent binary number and
combining all those digits we get the final binary equivalent.
Result: (010011101)2
Result: (001010011100)2
17
Step 2: Next we disregard the whole number part of the previous result
(the 1 in this case) and multiply by 2 once again. The whole number part
of this new result is the second binary digit to the right of the point. We
will continue this process until we get a zero as our decimal part or until
we recognize an infinite repeating pattern.
0.25x2 0.50 0
0.50x2 1.00 1 Result : (11001.101)2
18
3. Decimal to Hexadecimal Conversion
Result: (15.34)8.
19
5. Binary to Hexadecimal Conversion
Result: (15.58)16.
Result: (B5.58)16.
Result: (10011110.101011110010)2
20
BINARY ARITHMETICS
Binary Addition
The four basic rules for adding binary digits (bits) are as follows:
0 + 0 = 0 Sum of 0 with a carry 0
0 + 1 = 1 Sum of 1 with a carry 0
1 + 0 = 1 Sum of 1 with a carry 0
1 + 1 = 1 0 Sum of 0 with a carry 1
examples:
110
+ 100
1010
111
+ 011
1010
1111
+ 1100
11011
1011
1111
+ 110
100000
Binary Subtraction
The four basic rules for subtracting are as follows:
0–0=0
1–1=0
1–0=1
0 – 1 = 1 0-1 with a borrow of 1
examples:
11
- 01
10
11
- 10
21
01
101
- 011
010
110
- 101
001
101101
- 001110
11111
22
CHAPTER 3
PROGRAMMING CONCEPTS
Way of problem solving using a computer program includes the following steps:
Defining the Problem
State the problem you are trying to solve clearly and concisely (brief but
comprehensive).
Writing the Algorithm
As it is already defined algorithm is the set of the steps related with the
method of solution of a given problem. This should be done in a
programming manner. This step also includes writing the followings:
Pseudo-code
Flowchart
Writing the Program
Now the solution defined in the previous step is rewritten by using any
programming language (i.e. by obeying the rules of the used programming
language)
Testing and Debugging the Program
The final step is running the written computer program on a computer
and fixing the errors if there is any.
23
The symbols used in a flow chart:
Example
The final grade is calculated as the average of four marks. Student fails if final
grade is less than 50. Write an algorithm to determine a student’s final grade
and indicate whether it is passing or failing.
Algorithm
Input a set of 4 marks
Get the final grade by adding marks and dividing it by 4.
If the grade is below 50
then write “FAIL”
otherwise write “PASS”
24
Pseudocode
Step 1: START
Step 2: Input M1, M2, M3, M4
Step 3: GRADE ← (M1 + M2 + M3 + M4) / 4
Step 4: IF ( GRADE < 50 ) THEN
Print “FAIL”
ELSE
Print “PASS”
ENDIF
Step 5: END
Flowchart
25
Example
Write an algorithm that read two values, determines the largest values and
prints the largest values with an identifying massage.
Algorithm
Input two numbers
Compare the numbers and find the maximum
Print the message “the largest value is:” and value of MAX
Pseudocode
Step 1: START
Step 2: INPUT NUMBER1, NUMBER2
Step 3: IF NUMBER1 > NUMBER 2 THEN
MAX←NUMBER1
ELSE
MAX←NUMBER2
ENDIF
Step 4: PRINT “The largest value is:” , MAX
Step 5: END
Flowchart
26
DECISION STRUCTURES
Decision structures can test conditions and then depending on the results of that
test, perform different operations. There are more than one decision structure
such as:
IF structure
IF THEN ELSE structure
IF structure is as follows:
IF condition THEN
Here you may have one or more comments to the computer.
These comments will be executed if the condition is true.
Otherwise control passes directly to the next step after ENDIF.
ENDIF
Here condition is nothing but a logical operation such as A > B whose result is
either true or false.
27
Example: Write an algorithm/pseudo code that reads three numbers and prints
the value of the largest one. Also draw the flowchart.
Step 1: Start
Step 2: Input N1, N2, N3
Step 3: IF N1 > N2 THEN
IF N1 > N3 THEN
MAX ← N1
ELSE
MAX ← N3
ENDIF
ELSE
IF N2 > N3 THEN
MAX ← N2
ELSE
MAX ← N3
ENDIF
ENDIF
Step 4: Print “The largest number is”, MAX
Step 5: End
The IF structure given in the above example is known as NESTED IF. i.e. in IF
THEN block and/or in ELSE block involve another decision structure.
DRAW FLOWCHART
28
LOOPS
In computer programming, a loop is a sequence of instructions that is continually
repeated until a certain condition is reached.
Depending on the programming language used, different types of loops may be
available:
While loops
Repeat until loops
Do loops
For loops
While Loop
While loop has the following structure:
WHILE condition
The comments written between WHILE condition and END WHILE
will be executed if the condition is true. Then the condition will be
checked again and the block will be repeated once more. And this
will go on. If the condition is false the control passes to the next
step after the END WHILE without executing the while block.
END WHILE
Here condition is nothing but a logical operation such as A > B whose result is
either true or false.
29
Step 1: Start
Step 2: Base ← 2
Step 3: Power ← 12
Step 4: Product ← Base
Step 5: Counter ← 1
Step 6: WHILE Counter < Power
Step 7: Product ← Product *Base
Step 8: Counter ← Counter +1
END WHILE
Step 9: Print Product
Step 10: End
30
Example: Trace the above code for power = 4.
Base Power Product Counter Counter < Power
Step2 2 ? ? ? ?
Step3 2 4 ? ?
Step4 2 4 2 ?
Step5 2 4 2 1
Step6 2 4 2 1 1 < 4, True
Step7 2 4 2*2=4 1
Step8 2 4 4 1+1=2
Step6 2 4 4 2 2 < 4, True
Step7 2 4 4*2=8 2
Step8 2 4 8 2+1=3
Step6 2 4 8 3 3 < 4, True
Step7 2 4 8*2=16 3
Step8 2 4 16 3+1=4
Step6 2 4 16 3 4 < 4, False
Step9 Print 16
Base=2
Power=4
Product=2
Counter=1
Is Counter < Power (1<4) Yes 16
Product=2*2 (4)
Counter=1+1 (=2)
Is Counter < Power (2<4) Yes
Product=4*2 (=8)
Counter=2+1 (=3)
Is Counter < Power (3<4) Yes
Product=8*2 (=16)
Counter=3+1 (=4)
Is Counter < Power (4<4) NO
computer will print 16
31
Example: Write an algorithm and draw a flowchart in order to find and print the
following summation: sum= 1 + 2 + 3+ ….+ 100
Step 1: Start
Step 2: Sum ← 0
Step 3: Counter ← 1
Step 4: WHILE Counter <= 100
Step 5: Sum ← Sum + Counter
Step 6: Counter ← Counter +1
END WHILE
Step 7: Print Sum
Step 8: End
Example: Write an algorithm and draw a flowchart in order to find and print the
following summation:
sum= 3+ 5 + 7….+ 15
Step 1: Start
Step 2: Sum ← 0
Step 3: Counter ← 3
Step 4: WHILE Counter <= 15
Step 5: Sum ← Sum + Counter
Step 6: Counter ← Counter +2
END WHILE
Step 7: Print Sum
Step 8: End
Example: Write an algorithm and draw a flowchart in order to find and print the
following summation:
sum= 10+ 12 + 14….+ 56
Step 1: Start
Step 2: Sum ← 0
Step 3: Counter ← 10
Step 4: WHILE Counter <= 56
Step 5: Sum ← Sum + Counter
Step 6: Counter ← Counter +2
END WHILE
Step 7: Print Sum
Step 8: End
32
Example: Write an algorithm, draw a flowchart and trace the algorithm.
Algorithm will request the user to enter 5 number from the keyboard and print
the summation of the entered numbers. The program will check the number of
elements and doesn’t allow to enter more or less than 5 numbers.
Step 1: Start
Step 2: Print “Please enter an integer number”
Step 3: Input N
Step 4: IF N < 0 THEN
Step 5: Result ← N + 6
ELSE
Step 6: Result ← N * 2
ENDIF
Step 7: Print Result
Step 8: End
Example: Write an algorithm and draw a flowchart in order to find and print the
following summation:
sum= 13 + 33 + 63+ ….+ (2N-1)3 = ∑ 2 −1
where N is an integer which is going to be entered by the user.
33
Step 1: Start
Step 2: Print “Enter a positive integer number”
Step 3: Enter N
Step 4: Sum ← 0
Step 5: Counter ← 1
Step 6: WHILE Counter <= N
Step 7: Sum ← Sum + (2*Counter - 1)^3
Step 8: Counter ← Counter +1
END WHILE
Step 9: Print Sum
Step 10: End
Step 1: Start
Step 2: Print “Enter a positive integer number”
Step 3: Enter N
Step 4: Sum ← 0
Step 5: Counter ← 1
Step 6: IF Counter <= N THEN
Step 7: Sum ← Sum + (2*Counter - 1)^3
Step 8: Counter ← Counter +1
Step 9: GOTO Step 6
END WHILE
Step 9: Print Sum
Step 10: End
NOTE: by using GOTO statement you can directly access any desired step in the
code. Be careful, by using GOTO statement you can leave the Decision Structure
or the Loop Structure but you cannot directly access to any IF Then Block or Else
Block or While Block from outside the block.
Example: Write an algorithm and draw a flowchart in order to find and print the
following summation:
sum= 25 + 48 + 611+ ….+ (2N)3N+2 = ∑ 2
where N is an integer which is going to be entered by the user. If the user enters
a negative integer ask him/her to enter an integer number.
34
Step 1: Start
Step 2: Print “Enter a positive integer number”
Step 3: Enter N
Step 4: IF N < 0 THEN
Step 5: GOTO Step 2
ENDIF
Step 6: Sum ← 0
Step 7: Counter ← 1
Step 8: WHILE Counter <= N
Step 9: Sum ← Sum + (2*Counter)^(3*counter+2)
Step 10: Counter ← Counter + 1
END WHILE
Step 11: Print Sum
Step 12: End
35
36