Chapter One: What Is Computer?
Chapter One: What Is Computer?
Chapter One: What Is Computer?
CHAPTER ONE
Introduction to computer
What is computer?
A computer is an electronic machine, operating under the control of instructions stored in its own
memory that can accept data, manipulate the data according to specified rules, produce results, and store
the results for future use. Computers process data to create information. Data is a collection of raw or
unprocessed facts, figures, and symbols. Information is data that is organized, meaningful, and useful.
To process data into information, a computer uses hardware and software. Hardware is the electric,
electronic, and mechanical equipment that makes up a computer. Software is the series of instructions
that tells the hardware how to perform tasks.
Characteristics of computer
The characteristics of computers that have made them so powerful and universally useful are speed,
accuracy, diligence, versatility and storage capacity. Let us discuss them briefly.
In general a computer has a capacity to store a very large amount of information in organized manner
so that accessing information is very fast.
INTRODUCTION TO COMPUTER PROGRAMMING 2012 E.C
Types of Computers
Computers can be classified into different categories based on different characteristics.
Analog
Analog computers operate by measuring physical properties. They deal with continuous variables; they
don’t compute directly with numbers, rather, they operate by measuring physical magnitude such as
pressure, temperature, voltage, current etc.
Digital
Digital computers deal with discrete variables; they operate by counting rather than measuring. They
operate directly up on numbers (or digits) that represent numbers, letters, or other special symbols.
Hybrid
Hybrid computers inherit the best features of both analog and digital computers. Usually the
Input is continuous data (analog). Since Digital Processing is more accurate, processing takes
place digitally. The processed information – the output – could be either digital or analog,
depending on the user preference or the type of application.
Super computer
The term supercomputer has been coined to describe a category of extremely powerful computer designed
for high-speed processing. A supercomputer is generally characterized as being the fastest, most
powerful, and most expensive computer.
INTRODUCTION TO COMPUTER PROGRAMMING 2012 E.C
i) Input Devices
ii) Storage Devices
iii) Output Devices
iv) Central Processing Unit (CPU)
i) Input Devices
Input devices are used to enter information into computer. They convert the data we give them into
the form that can be manipulated in the computer (electronic format).
Some examples of input devices are Keyboard, mouse, scanner, Bar Code Reader, mice
1 GHz = 1000MHZ
Current CPUs are as fast as 2-3GHz (2-3 billion cycles per second)
Control Unit
As human brain controls the body, control unit controls the computer hardware. Control Unit
does not execute instruction by itself, i.e. does not carry out instruction processing, but it directs
other processing elements to execute instructions.
Arithmetic operation
Logic Operation
Arithmetic operation: this includes mathematical operations like addition, subtraction,
multiplication, division, etc. If you give your computer the instruction 2+3, this will be included
in arithmetic operation and it is executed by Arithmetic Unit.
Logical Operation: this is concerned with the comparison of data and it is called logical
operation. It includes operators like less than, greater than, equal to, less or equal to, greater or
equal to, different from, etc. e.g. if mark>80, grade is 'A'.
Examples
Primary memory, also called Main memory, refers to integrated circuit that stores program instructions
and data. The CPU closely works with the main memory to perform its activities. Memory stores three
things:
Why is it volatile? It uses electric power to store data. When you write anything on your computer, first it
is stored on RAM. When you save the file, it is transferred into secondary storage.
RAM has differing capacity, the common ones being 128, 256, and 512.It is directly accessible by CPU.
It is called RAM because each memory location can be accessed randomly using memory address. Each
unit in RAM has memory address by which it can be easily accessed/referenced.
ROM stores data and programs that are permanently required by the computer. They have programs built
into them at the factory and that program could not be changed or erased by the user, but read. It is non-
volatile, read-only (not changeable) memory. Read-only means data can't be altered or erased but read.
2. Secondary Storage
Secondary storage (also called auxiliary storage) supplements the primary memory. It takes many forms.
It includes punched cards, punched paper tape, magnetic tape, magnetic disk and optical disk.
Computer Software
Computer hardware is directed by a set of instructions. Without these instructions, computers can do
nothing. These set of instructions are called software (also called programs). One or more programs are
termed as software. We use programming languages to write these instructions. Examples of
programming languages include C, C++, Java, etc.
INTRODUCTION TO COMPUTER PROGRAMMING 2012 E.C
System Software
Application Software
System Software
System software consists of programs that are related to controlling the actual operations of the
computer equipment/resource.
Operating System
Utility Software
Language translators
Operating system manage resources, provides a user interface, and run application software. It
organizes resources such as keyboard, mouse, printer, monitor, etc. It also presents GUI (Graphical User
Interface) to the user for easy use of computer. It makes complex hardware more users friendly i.e. it acts
between the user and hardware. Operating system coordinates the activity between the user and the
computer
Utilities software is programs that make computing easier. They perform specific tasks related to
managing computer resources or files. There are different utility programs:
i) Troubleshooting programs: enable us to recognize and correct computer problems before they
become serious.
ii) Anti-virus programs: they protect your computer against viruses or other malicious programs
that damage computer.
iii) File compression programs: are used to reduce the size of files or data so that it takes less
storage space or network band. E.g WinZip, WinRAR, etc.
iv) Uninstall programs: this software enable us to safely and completely remove unneeded
programs/software from your computer.
v) Back up software: with the help of this software, we can make copies of files to be used in
case of the original data is lost/damaged. This copy is called back up.
vi) Screen savers: helps to prevent your work from being seen by others if you leave your
computer idle for some time.
Language translators are used to convert the programming instruction written by users into binary
code that the computer can understand. They are written for specific programming languages and
computer system.
INTRODUCTION TO COMPUTER PROGRAMMING 2012 E.C
Application Software
Application software performs useful work for the user. These useful works could be:
9 9 11 1001
10 A 12 1010
11 B 13 1011
12 C 14 1100
13 D 15 1101
14 E 16 1110
15 F 17 1111
16 10 20 0001 0000
2. The second reason is that the computer circuits only have to handle two binary digits rather
than ten decimal digits. This greatly simplifies the internal circuit design of computers, resulting
in less expensive & more reliable circuits.
3. Finally, the binary system is used because everything that can be done in decimal number system
(addition, subtraction, division & multiplication) can also be done in binary number system.
Bytes
Most computers work with groups of 8 bits, which is called a byte. To make it easier to read, the 8
binary digits in a byte are divided into two groups of four, called nibbles, when they are written.
One byte may hold binary numbers ranging in value from 0000 0000 (base 2) to 1111 1111 (base 2),
or from 0 (base 10) to 255 (base 10). Counting 0 as a value, one byte can contain 256 values. For
many computer variables, the maximum value is 255 because the computer wants to store the value in
a single byte, or you are limited to 256 choices.
Words
- Bytes are combined into groups of 1 to 8 bytes called words.
- Words refer to the number of bits that a computer process at once.
- Typically word lengths are 8 bits, 16 bits, 32 bits & 64 bits.
A decimal integer is converted to any other base, by using the division operation.
INTRODUCTION TO COMPUTER PROGRAMMING 2012 E.C
0-9 = 0-9
A = 10 D = 13
B = 11 E = 14
C = 12 F = 15
59 is 3B in hexadecimal
A binary number can be converted into octal or hexadecimal number using a shortcut method.
The shortcut method is based on the following information:-
Steps 1 - Divide the decimal number to be converted by the value of the new base.
Step 2 - Get the remainder from Step 1 as the rightmost digit (least significant digit) of new base
number.
Step 3 - Divide the quotient of the previous divide by the new base.
Step 4 - Record the remainder from Step 3 as the next digit (to the left) of the new base number.
Repeat Steps 3 and 4, getting remainders from right to left, until the quotient becomes zero in Step 3.
The last remainder thus obtained will be the most significant digit (MSD) of the new base number.
1.3.1 Example
Step 1 29 / 2 14 1
Step 2 14 / 2 7 0
Step 3 7/2 3 1
Step 4 3/2 1 1
Step 5 1/2 0 1
As mentioned in Steps 2 and 4, the remainders have to be arranged in the reverse order so that the first
remainder becomes the least significant digit (LSD) and the last remainder becomes the most significant
digit (MSD).
Steps
Steps 1 - Determine the column (positional) value of each digit (this depends on the position of
the digit and the base of the number system).
Step 2 - Multiply the obtained column values (in Step 1) by the digits in the corresponding
columns.
Step 3 - Sum the products calculated in Step 2. The total is the equivalent value in decimal.
INTRODUCTION TO COMPUTER PROGRAMMING 2012 E.C
1.4.1 Example
Steps
1.5.1 Example
Step 1 21 / 2 10 1
INTRODUCTION TO COMPUTER PROGRAMMING 2012E.C
Step 2 10 / 2 5 0
Step 3 5 / 2 2 1
Step 4 2 / 2 1 0
Step 5 1 / 2 0 1
Steps
Step 1 - Divide the binary digits into groups of three (starting from the right).
Step 2 - Convert each group of three binary digits to one octal digit.
1.5.4 Example
Step 2 101012 28 58
An easy way to convert from binary to octal is to group binary digits into sets of three, starting with the
least significant (rightmost) digits.
011 100 101 Pad the most significant digits with zeros if
necessary to complete a group of three.
INTRODUCTION TO COMPUTER PROGRAMMING 2012 E.C
Octal: 0 1 2 3 4 5 6 7
Steps
Steps 1 - Convert each octal digit to a 3-digit binary number (the octal digits may be treated as
decimal for this conversion).
Step 2 - Combine all the resulting binary groups (of 3 digits each) into a single binary number.
1.6.1 Example
Converting from octal to binary is as easy as converting from binary to octal. Simply look up each octal
digit to obtain the equivalent group of three binary digits.
Octal: 0 1 2 3 4 5 6 7
Octal = 3 4 5
Steps
Step 1 - Divide the binary digits into groups of four (starting from the right).
Step 2 - Convert each group of four binary digits to one hexadecimal symbol.
1.6.2 Example
An equally easy way to convert from binary to hexadecimal is to group binary digits into sets of four,
starting with the least significant (rightmost) digits.
Hexadecimal: 0 1 2 3 4 5 6 7
Hexadecimal: 8 9 A B C D E F
INTRODUCTION TO COMPUTER PROGRAMMING 2012 E.C
Hexadecimal = E 5 = E5 hex
Example
Steps
Steps 1 - Convert each hexadecimal digit to a 4-digit binary number (the hexadecimal digits may
be treated as decimal for this conversion).
Step 2 - Combine all the resulting binary groups (of 4 digits each) into a single binary number.
1.8.1 Example
Converting from hexadecimal to binary is as easy as converting from binary to hexadecimal. Simply look
up each hexadecimal digit to obtain the equivalent group of four binary digits.
Hexadecimal: 0 1 2 3 4 5 6 7
Hexadecimal: 8 9 A B C D E F
Hexadecimal = A 2 D E
When converting from octal to hexadecimal, it is often easier to first convert the octal number into binary
and then from binary into hexadecimal. For example, to convert 345 octal into hex:
Drop any leading zeros or pad with leading zeros to get groups of four binary digits (bits):
Binary 011100101 = 1110 0101
Hexadecimal: 0 1 2 3 4 5 6 7
Hexadecimal: 8 9 A B C D E F
Hexadecimal = E 5 = E5 hex
Therefore, through a two-step conversion process, octal 345 equals binary 011100101 equals hexadecimal
E5.
INTRODUCTION TO COMPUTER PROGRAMMING 2012 E.C
When converting from hexadecimal to octal, it is often easier to first convert the hexadecimal number into
binary and then from binary into octal. For example, to convert A2DE hex into octal:
Add leading zeros or remove leading zeros to group into sets of three binary digits.
Octal: 0 1 2 3 4 5 6 7
Therefore, through a two-step conversion process, hexadecimal A2DE equals binary 1010001011011110
equals octal 121336.
Converting hexadecimal to decimal can be performed in the conventional mathematical way, by showing
each digit place as an increasing power of 16. Of course, hexadecimal letter values need to be converted
to decimal values before performing the math.
Hexadecimal: 0 1 2 3 4 5 6 7
Decimal: 012 3 4 5 6 7
Hexadecimal: 8 9 A B C D E F
Decimal: 8 9 10 11 12 13 14 15
A2DE hexadecimal:
INTRODUCTION TO COMPUTER PROGRAMMING 2012 E.C
Hexadecimal
Decimal Number Operation Quotient Remainder
Result
1792 ÷ 16 = 112 0 0
112 ÷ 16 = 7 0 00
7 ÷ 16 = 0 7 700
0 Done.
The only addition to the algorithm when converting from decimal to hexadecimal is that a table must be
used to obtain the hexadecimal digit if the remainder is greater than decimal l 9.
Decimal: 01234567
Hexadecimal: 0 1 2 3 4 5 6 7
Decimal: 8 9 10 11 12 13 14 15
Hexadecimal: 8 9 A B C D E F
Example:
Understanding Kilobytes, Megabytes, and Gigabytes
A kilobyte is often referred to as 1,000 bytes, but this is not totally accurate. In computer terms, a
kilobyte is 1,024 bytes. K is used as shorthand for 210, which equals 1,024.
A megabyte is not exactly 1,000,000 bytes, but 220 bytes, or 1,024 KB, or 1,048,576 bytes. A 200
MB drive can store 204,800 KB or 209,715,200 bytes.
A gigabyte is not 1 billion bytes, but 230 bytes or 1,073,741,824 bytes. 3 GB is the same as
3,221,225,472 bytes.
For Example
INTRODUCTION TO COMPUTER PROGRAMMING 2012 E.C
Machine Language: is a low level language in which its instructions are string of binary
representation that a computer's hardware can understand and perform.
e.g. 100100 010001
Assembly Language: it is also a low-level programming language in which a mnemonic or a symbol
is used to represent each of the machine language instructions for a specific computer. Assembly
language programs also allow the user to use text names for data rather than having to remember their
memory addresses. The Assembly language is translated into the machine language through an
Assembler.
High Level Language: The codes in high-level languages are similar to everyday English, closer to
standard notations and it uses ordinary mathematical notations. e.g. C++, Basic, Fortran, Cobol. The
High Level Language is translated to Machine language through Compilers.
INTRODUCTION TO COMPUTER PROGRAMMING 2012 E.C
1. Pseudocode
Pseudocode is an artificial and informal language that helps programmers develop algorithms.
Pseudocode is similar to natural language, yet close enough to programming language that it can be easily
converted later into program source code. By writing the algorithm in pseudocode first, the programmer
can focus on just the logical steps the program must perform, without having to worry yet about syntax or
about details such as how output will be displayed.
Example 1: Write an algorithm, in pseudocode, for a program that take two numbers and output
the sum of the two numbers.
Algorithm
Step 1: Input two numbers say N1 and N2
Step 2: Calculate the sum N1 + N2
Step 3: out put the sum
Pseudocode
Input N1 and N2
Add N1 and N2
Output N1 and N2
Example 2: Write an algorithm to determine a student’s final mark and indicate whether it is
passing or failing. The final mark is calculated as the average of six marks
Algorithm
Step 1: Input the six marks M1, M2, M3, M4, M5, M6
Step 2: Calculate the average of the six marks
Average = ( M1, M2, M3, M4, M5, M6 )/ 6
Step 3: Check if the Average is greater than 50.
Step 4: if the average is greater than 50 then print (Output) Pass else i.e. if it is below 50 then
print Fail.
Pseudocode
Input M1, M2, M3, M4, M5, M6
Calculate Average= (M1, M2, M3, M4, M5, M6)/ 6
If average is below 50
Print “FAIL”
Else
Print “PASS”
Exercise: Write an algorithm and pseudocode for the following problems
a. Take a number and calculate the factorial of that number
b. Take a number and prints “odd” if the number is odd otherwise prints “even”
c. Calculate the CGPA of a student. (The student should enter grade for the five subjects along
with the respective credit hour).
2. Flowcharts
A flowchart is a diagram that shows the logical flow of a program. It is a useful tool for
planning each operation a program must perform, and the order in which the operations are to
occur. The logical flow of an algorithm can be seen by tracing through the flowchart. Some
standard symbols used in the formation of flow charts are given below.
Flow Chart Symbols
INTRODUCTION TO COMPUTER PROGRAMMING 2012 E.C
Example 1: Write an algorithm, in flow chart form that take two numbers and output the
sum of the two numbers.
Algorithm
Step 1: Input two numbers say N1 and N2
Step 2: Calculate the sum N1 + N2
Step 3: out put the sum
Flow chart
INTRODUCTION TO COMPUTER PROGRAMMING 2012 E.C
Example 2: Write an algorithm in flow chart form to determine a student’s final mark and
indicate whether it is passing or failing. The final mark is calculated as the average of six marks.
Flow chart
The flowchart shows the software development cycle. In software development cycle,
you basically design the system, code it and test it. When an error is found, it must be
determined whether the error is a design error or not. Coding errors can quickly be fixed,
but design errors may take longer.
INTRODUCTION TO COMPUTER PROGRAMMING 2012 E.C