You are on page 1of 129

College of Engineering

Ateneo De Naga University

Course Code : COES213


Course Title : Computer Programming
Credit/ No. of Units : 2 units
Duration/ Term : 1st Sem. S/ Y 2013-2014
Instructor : Robert John F. Buena, CpE
Consultation Hours : T-TH: 10:30am – 1:30pm
Friday: 10:30am – 12nn
Consultation Venue : Engineering Faculty Lounge
E-mail Address : rjbuena@gmail.com
rjbuena@mbox.adnu.edu.ph
Course Description
 This course provides a basic understanding of the
information technology concepts; fundamentals of
algorithm development; high-level language and
programming applications; and computer solutions
of engineering problems.
Course Learning Outcomes (COs):
At the end of the course the student should be able
to :
CO1. Explain the basic information technology
concepts.
CO 2. Compute for different number base
conversion and data representation.
CO 3. Generate an effective algorithm using a high-
level programming language.
CO 4. Apply computer programming concepts using
C++ language.
CO 5. Develop programs that solve given problem
specifications.
Course Outline
1. Computer fundamentals
2. Number System and Data Representation
3. Introduction to Programming
4. Basic of C++
5. Control Structures and Functions
6. Advanced Data Types

4
Grading System
Grading System:
Midterm Examination 20%
Final Examination 20%
Class standing 60%
Class Standing is composed of:
Quizzes 18%
Laboratory Activities 12%
Seatwork/ Assignment 6%
Course Project 24%

5
House Rules
1. Permit
2. Delayed Exam
3. Major Exams
4. Deadline
5. Cheating
6. Attendance
7. Uniform

6
Textbook:
Problem Solving with C++, 7th Edition
By: Walter Savitch
References:
C++ for Engineers and Scientist
By: Gary J. Bronson
SAMS Teach Yourself C++ in 24 Hours
By: Jesse Liberty
C++ How to Program
By: Deitel and Deitel
Moodle Account
http://adnuengineering.net
username = <school id number>
password = AdnuEngg123!

change your password and (valid) email address


right after logging in.
(On the upper right corner, click on Edit Profile
tab)

Enrollment key = programmingcomputer


8
Formatted Paper 0.5”

0.5” 0.5”

1.0”
0.5”
Bonus Activity
Bonus Quiz
Assignment
1. Read and study the basic computer concepts, hardware and
software.
2. Identify and define the basic operation/fundamental function of a
computer system.
3. Describe hardware and software.
4. Identify and define the six logical units or sections of a
computer system.
5. Identify and define the general types of programming language.

For numbers 2 to 5 write it in a formatted paper.

12
College of Engineering
Ateneo De Naga University

Welcome to
Computer Programming

Robert John F. Buena, CpE


Instructor
Part 1
I. Computer fundamentals
A. Basic Computer Concepts
B. Hardware
C. Software
Objectives
 Describe the basic operation of computer
system.
 Identify the hardware and software
components.
 Define programming language.
 Identify the general types of programming
language.
Why do we need to study the basic
operation of computer system?
Knowledge of the basic computer system
concepts clearly understand the structure of the
computer to be able to develop solutions to
problems, and to use the computer as a tool to
execute the solutions to problems.
Computer Systems

 A computer (or computer system) is an electronic


machine that can carry out specific tasks by following
sequences of instructions.
 It is controlled by a set of instructions called
programs.
 An electronic device that processes data, converting it
into information that is useful to people.
 The computer is a machine that can perform various
tasks under control of the software.
Fundamental functions
 Input involves entering data into the computer
for processing.
 Processing executes the instructions in
memory to perform some transformation
and/or computation on the data also in
memory.
 Output involves transferring data from the
computer to an output.
Two important types of components in
computer system:

 Hardware is the physical parts or components


of a computer system.
◦ Processor, memory, disk unit, keyboard, screen, and
others
 Software is a collection of programs and
related data that provide the instructions.
◦ System software and application software
Hardware Components

 The Central Processing Unit (CPU)


 Main memory, also known as random
access memory (RAM)
 The Storage Devices
 The main input/output (I/O) devices
connected to the communication ports
Basic Hardware Structure
Input Devices

 Devices that allows a person to communicate


information to the computer.
 The "receiving" section of the computer.
 Entering data and/or programs into the
computer.
 Primary input devices are likely to be a
keyboard and a mouse.
Output Devices

 Allows the computer to communicate


information to us.
 The "shipping" section of the computer.
 It takes information that has been processed by
the computer
 Make the information available for use outside
the computer.
 The most common output device is a display
screen, referred to as a monitor.
Main Memory
 Also called random access memory (RAM).
 This is the rapid access, relatively low-capacity
"warehouse" section of the computer
 It retains information that has been entered
through the input unit for processing.
 The memory unit also retains processed
information until that information can be placed
on output devices by the output unit.
Main Memory

 Consists of a large number of storage cells; each


one is called a memory cell/memory locations.
 Each memory location contains a string of
zeros and ones.
 Each of these cells has an associated memory
location, which is known as a memory address.
 A digit that can assume only the values zero or
one is called a binary digit or a bit.
 An eight-bit portion of memory is called a byte
Main Memory
 Main memory is divided into
numbered locations called bytes.
 The number associated with a byte
is called its address.
Logic Diagram for 74AHC573
Storage Devices
 Long-term, high-capacity "warehousing" section of the
computer.
 Provide permanent storage until the user decides to erase
the data and/or programs.
 Programs or data not actively being used by the other
units normally are placed on secondary storage devices.
 Information in secondary storage is kept in units called
files.
Central processing unit (CPU)
 The "administrative" section of the computer.
 Coordinates and responsible for supervising the
operation of the other sections.
 Capable of executing the instructions that are stored in
memory.
 Carrying out arithmetic operations, and performing data
transfers.
Example of Program Execution

0001 = Load AC from memory,


0010 = Store AC to memory,
0101 = Add to AC from memory

Program counter (PC) = Address of


instruction,
Instruction register (IR) = Instruction
being executed, Accumulator (AC) =
Temporary storage
Units located in the CPU
 Control Unit is responsible for obtaining
instruction’s from the memory.
 Arithmetic and Logic unit (ALU), performs
all the arithmetic and logic functions for the
computer.
Software Components

 The hardware components are driven and


controlled by the software components.
 The software components consist of the set of
programs that execute in the computer.
 These programs control, manage, and carry out
important tasks.
Structure of a program

o Data descriptions, which define all the data to be


manipulated and transformed by the instructions
o A sequence of instructions, which defines all the
transformations to be carried out on the data in order to
produce the desired results
Simple view of running program
Types of software components:
 System software is a collection of programs
that control the activities and functions of the
various hardware components.
 Application software consists of those
programs that solve specific problems for the
users.
Programming Languages

 A programming language is a formal


notation that is used to write the data
description and the instructions of a
program.
 The language has a well-defined set of
syntax and semantic rules.
 Syntax rules describe how to write
sentences.
 Semantic rules describe the meaning of
the sentences.
Machine Languages, Assembly Languages,
and High - Level Languages
 Machine language is the "natural language"
of a particular computer.
 Machine languages consist of strings of
numbers that instruct computer to perform
it’s operations one at a time.
 Machine languages are machine-dependent.
Low level language
 The word "low" refers to the small or
nonexistent amount of abstraction between
the language and machine language.
 Can be converted to machine code without
using a compiler or interpreter,
 Resulting code runs directly on the
processor.
 For example: ADD X Y Z
Assembly Languages

 These languages were developed to ease and


improve the construction of programs.
 Translator programs called assemblers were
developed to convert assembly-language
programs to machine language.
 In these languages, various mnemonic symbols
represent operations and addresses in memory.
 These languages are also low-level and
hardware dependent.
Assembly Languages

 LOAD BASEPAY
 ADD OVERPAY
 STORE GROSSPAY
 ADD X Y Z
◦ ADD might translate to 0110, the X might
translate to 1001, the Y to 1010, and the Z to
1011.
◦ 0110 1001 1010 1011
High-Level Programming Languages

 Write instructions that look almost like


everyday English and contain commonly used
mathematical notations .
 Hardware independent and closer to the
problem to be solved.
 Translator programs called compilers convert
high- level language programs into machine
language.
 C and C++ are among the most powerful and
most widely used high-level languages.
High-Level Programming Languages

 Payroll program written in a high- level language


might contain a statement such as :
◦ gross Pay = base Pay + overTimePay
 Expressive enough to help the human in the
writing of programs for a large family of
problems.
 Examples of these languages are Pascal, C,
Cobol, FORTRAN, Algol, Ada, Smalltalk,
C++, Eiffel, and Java.
Compiler
 Program that translates a high-level language
program into a machine-language.
 Sort of program, its input or data is some other
program, and its output is yet another program.
 The input program is usually called the source
program or source code,
 The translated version produced by the compiler
is called the object program or object code.
Linking
 The object code for your C++ program
must be combined with the object code for
routines (such as input and output routines)
that your program uses.
 The process of combining object code is
called linking and is done by a program
called a linker.
Basics of a Typical C++ Environment
Editor
Program is created in
Disk
the editor and stored
on disk.
Phases of C++ Preprocessor Disk Preprocessor program
processes the code.
Programs: Compiler Disk
Compiler creates
object code and stores
1. Edit it on disk.
Linker links the object
Linker Disk code with the libraries,
2. Preprocess creates a.out and
Primary stores it on disk
3. Compile Loader
Memory

4. Link Disk
Loader puts program
in memory.
..

5. Load ..
..

Primary
6. Execute CPU
Memory
CPU takes each
instruction and
executes it, possibly
.. storing new data
..
.. values as the program
executes.
Assignment No. 2
1. Identify the basic data units.
2. Identify the number systems and its different bases.
3. Show your complete solution.
Part 1I
II. Number System and Data
Representation
- Introduction to Number Systems
- Number System Conversion
- Data Representation
Objectives
 Identify the number system and its different bases
 Compute for different number base conversions
 Describe the importance of number systems in relation
to computers and its applications
 Discuss the different data representation.
INTRODUCTION

• A number system defines how a number


can be represented using distinct symbols.
• A number can be represented differently in
different systems.
• For example, the two numbers (2A)16 and
(52)8 both refer to the same quantity, (42)10,
but their representations are different.

2.53
Positional Number Systems
 The traditional number
system is called a
positional number system. 6354  6 *1000  3 *100  5 *10  4
 A number is represented
as a string of digits. p 1
 Each digit position has a D   di 10 i
weight assoc. with it.
i 0
 Number’s value = a
weighted sum of the digits
Radix/Base

300010 = 3 * 10 3 Exponent

Radix and “weight”


 Decimal numbers’ “weight” and its meaning
 “10” is called “Radix”
 upper right of 10 (in this example, 3) is called “exponent”
 Binary digit’s “weight” and its meaning
Positional Notation – more examples
Value of number is determined by multiplying each digit by a
weight and then summing. The weight of each digit is a
POWER of the BASE and is determined by position.

953.78 = 9 x 102 + 5 x 101 + 3 x 100 + 7 x 10-1 + 8 x 10-2


= 900 + 50 + 3 + .7 + .08 = 953.78
decimal

1011.11 = 1x23 + 0x22 + 1x21 + 1x20 + 1x2-1 + 1x2-2


= 8 + 0 + 2 + 1 + 0.5 + 0.25
= 11.75
binary

A2F = 10x162 + 2x161 + 15x160


= 10 x 256 + 2 x 16 + 15 x 1
= 2560 + 32 + 15 = 2607
hex
Terminology
Binary Digits (Bits)
 Two levels of status in computer’s electronic circuits
 Whether the electric current passes through it or not
 Whether the voltage is high or low
 1 digit of the binary system represented by “1” or “0”
 Smallest unit that represents data inside the computer
 1 bit can represent 2 values of data, “0” or “1”
 2 bits can represent 4 different values
 “00”, “01”, “10”, “11”
Bit representation

Open (0) or closed (1)


Not flowing (0) or flowing (1)

Off (0) or on (1)


 Use 1’s and 0’s to represent decimal
numbers.
 A BIT (1 OR 0) is the smallest unit of
memory in a computer.
• 1 bit – 1 or 0 (two different numbers)
• 2 bits – 00, 01, 10, 11 (four numbers)
• 3 bits – 000, 001, 010, 011, 100, 101,
110, 111 – (8 different numbers)
 How many different numbers can you
represent with?
◦ 4 bits?
◦ 5 bits?
◦ 6 bits?
◦ 8 bits?

 Number of bits ^ 2
 Taking an example using 8 bits
 256 individual combinations we can make

• 128 64 32 16 8 4 2 1
• Lowest number we can represent
0 0 0 0 0 0 0 0
• Highest number we can represent
1 1 1 1 1 1 1 1
• We simply add up the numbers with a 1
• 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1
 We want to represent the number 83 in binary
 (there’s a couple of ways of working it out)
• 128 64 32 16 8 4 2 1
0 (coz 128 don’t fit!)
1 (64 fits, leaves 19)
0
1 (leaves 3)
0 0
Gives us 1 (1 left)
1
0 1 0 1 0 0 1 1
Terminology
Bytes
 A byte is a unit that represents with 8 bits 1 character or
number, 1 byte = 8 bits
 E.g. “00000000”, “00000010”, etc.
 1 bit can be represented in 2 ways, i.e. combination of 8 bit
patterns into 1 byte enables the representation of 28 = 256
types of information
 Using a 1-byte word, 256 different characters can be
represented – sufficient for most Western character sets
 Two bytes are connected to obtain 16 bits, 216 = 65,536
 A 2-byte word
(or
Table)

(or Row)

(or Column)
Numeric Systems
 Also known as Base Systems or Radix
Systems
 Available digits:
Decimal system (base 10)
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Binary system (base 2)
0, 1
Octal system (base 8)
0, 1, 2, 3, 4, 5, 6, 7
Hexadecimal (base 16)
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
where A=10,B=11,C=12,D=13,E=14,F=15
Decimal Number
system

 Decimal number system contains 10 digits:


0,1,2,3,4,5,6,7,8,9; and that is why its base or
radix is 10.
 To indicate digits greater than 9 (nine) we shall
use the sum of these digits times power of 10.
Fractional DECIMAL
SYSTEM

 The decimal system is composed of 10 numerals or symbols.


These 10 symbols are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9; using these
symbols as digits of a number, we can express any quantity.
The decimal system, also called the base-10 system because it
has 10 digits.

1
10 4 103 10 2 101 100 10 10 2 10 3 10 4 105
Decimal Number
System
• The decimal number system is a positional
number system.

• Example:
5 6 2 1 1 X 100 = 1
103 102 101 100 2 X 101 = 20
6 X 102 = 600
5 X 103 = 5000
Binary Number
System
• The binary number system is also a positional
numbering system.

• Instead of using ten digits, 0 - 9, the binary system


uses only two digits, 0 and 1.
Binary Number
System

• The binary number system is also known as


base 2. The values of the positions are
calculated by taking 2 to some power.

• Why is the base 2 for binary numbers?


o Because we use 2 digits, the digits 0 and 1.
Fractional BINARY SYSTEM

 In the binary system, there are only two symbols or possible


digit values, 0 and 1. This base-2 system can be used to
represent any quantity that can be represented in decimal or
other number system.

24 23 22 21 20 2 1 2 2 2 3 2 4 2 5
Octal Number
System

 Also known as the Base 8 System


 Uses digits 0 - 7
 Readily converts to binary
 Groups of three (binary) digits can be used to
represent each octal digit
 Also uses multiplication and division algorithms
for conversion to and from base 10
Fractional OCTAL
NUMBER SYSTEM
 The octal number system has a base of eight, meaning that it
has eight possible digits: 0,1,2,3,4,5,6,7.

84 83 82 81 80 81 82 83 84 85


• Use to represent long binary numbers in computers and
microprocessors.
Hexadecimal Number
System
 Base 16 system
 Uses digits 0-9 &
letters A,B,C,D,E,F
 Groups of four bits
represent each
base 16 digit
Fractional HEXADECIMAL
NUMBER SYSTEM

 The hexadecimal system uses base 16. Thus, it has 16 possible


digit symbols. It uses the digits 0 through 9 plus the letters A,
B, C, D, E, and F as the 16 digit symbols.

16 4 163 16 2 161 160 16 1 16 2 16 3 16 4 16 5

• Use to represent long binary numbers in computers and


microprocessors.
• These digits can use to program machine language.
Numeric Data
Representation
Radix/Base Conversion
 In order to process numeric values in a computer,
decimal numbers are converted into binary or
hexadecimal numbers
 This operation is called radix conversion
 The following radix/base conversion techniques will be
discussed:
1. Decimal to Binary
2. Binary to Decimal
3. Binary to Hexadecimal
4. Hexadecimal to Binary
5. Octal to Binary
6. Binary to Octal
Decimal to Binary (Integer)
1. Decimal integer is divided into 2
2. The quotient and remainder are
obtained
3. The quotient is divided into 2 again until
the quotient becomes 0
4. The binary value is obtained by placing
the remainder(s) in reverse order
12510 = ?2 2 125 remainder
2 62 1
2 31 0
2 15 1
2 7 1
2 3 1
2 1 1
0 1

12510 = 11111012
Decimal to Binary
Decimal to Binary (Fraction)
 Decimal fraction is multiplied by 2
◦ Resulting integer portion is extracted (always be “0” or “1”)
◦ Resulting fraction portion is multiplied by 2
◦ Operation is repeated until the fraction portion becomes 0
 When decimal fractions are converted into binary
fractions, most of the times, the conversion is not
finished, since no matter how many times the fraction
portion is multiplied by 2, it will not become 0. Most
decimal fractions become infinite binary fractions.
Decimal to Binary (Fraction)
Find the binary equivalent of (0.75)10.

Number to be recorded
 0.75 × 2 = 1.50 1
 0.50 × 2 = 1.00 1
 Thus (0.75)10= (0.11)2.
Find the binary equivalent of (0.9)10.
Number (to be recorded)
 0.9 × 2 = 1.8 1
 0.8 × 2 = 1.6 1
 0.6 × 2 = 1.2 1
 0.2 × 2 = 0.4 0
 0.4 × 2 = 0.8 0
 0.8 × 2 = 1.6 1
 0.6 × 2 = 1.2 1
 0.2 × 2 = 0.4 0
 0.4 × 2 = 0.8 0
 0.8 × 2 = 1.6 1
 0.6 × 2 = 1.2 1
 0.2 × 2 = 0.4 0
 0.4 × 2 = 0.8 0
 0.8 × 2 = 1.6 1
 0.6 × 2 = 1.2 1
 0.2 × 2 = 0.4 0
Thus (0.9)10 = (0.111001100110011001)2.
 0.4 × 2 = 0.8 0
 0.8 × 2 = 1.6 1
 Decimal to binary .14579
x 2
3.14579 0.29158
x 2
0.58316
x 2
1.16632
x 2
0.33264
x 2
0.66528
x 2
1.33056
11.001001...
etc.
Binary to Decimal (integer)
◦ Multiply each bit by 2n, where n is the
“weight” of the bit
◦ The weight is the position of the bit,
starting from 0 on the right
◦ Add the results
Example- Convert (101101)2 into decimal number.
Binary to Decimal (integer)
Bit “0”

1010112 => 1 x 20 = 1
1 x 21 = 2
0 x 22 = 0
1 x 23 = 8
0 x 24 = 0
1 x 25 = 32
4310
Example- Convert (101101.11)2 into decimal number.
Binary to Decimal (fractions)

10.1011 => 1 x 2-4 = 0.0625


1 x 2-3 = 0.125
0 x 2-2 = 0.0
1 x 2-1 = 0.5
0 x 20 = 0.0
1 x 21 = 2.0
2.6875
Binary to Hexadecimal
 4-bit binary strings are equivalent to 1
hexadecimal digit
 The binary number is divided into groups
of 4 digits starting from the decimal point
 In the event that there is a bit string with
less than 4 digits, the necessary number of
0’s is added and the string is considered
as a 4-bit string
Binary to Hexadecimal
Binary to Hexadecimal
Binary to Hexadecimal
10101110112 = ?16

10 1011 1011

=(1x2^1)+(1x2^0) (1x2^3)+(0x2^2) (1x2^3)+(0x2^2)


+(1x2^1)+(1x2^0)+(1x2^1)+(1x2^0)
= 2*1 8+2+1 8+2+1
= 2 11 11
= 2 B B

10101110112 = 2BB16
Binary to Hexadecimal (Fraction)
Binary to Hexadecimal (Fraction)
Binary to Hexadecimal (Fraction)
101011.10112 = ?16

10 1011 1011

=(1x2^1)+(1x2^0) (1x2^3)+(0x2^2) (1x2^3)+(0x2^2)


+(1x2^1)+(1x2^0)+(1x2^1)+(1x2^0)
= 2*1 8+2+1 8+2+1
= 2 11 11
= 2 B B

10101110112 = 2B.B16
Hexadecimal to Binary
 Convert each hexadecimal digit to its 4-bit binary
equivalent.
 Combine all the binary numbers.
Hexadecimal to Binary (Integer)
 1 digit of the hexadecimal number is
represented with a 4-digit binary number
Hexadecimal to Binary (Fraction)
 Same technique as per integer
Hexadecimal to Binary (Fraction)
Octal to Binary
 Convert each octal digit to a 3-bit equivalent
binary representation.
 Combine the 3-bit section by removing the
spaces to get the binary number.

Use decimal to binary


conversion
Octal to Binary

Use decimal to binary


conversion
Octal to Binary
7058 = ?2

7 0 5

111 000 101

Use decimal to binary 7058 = 1110001012


conversion
Octal to Binary
 Convert 1038 to its binary form

Use decimal to binary


conversion
Octal to Binary (fraction)

Use decimal to binary


conversion
Binary to Octal
 Break the number into 3-bit sections starting from LSB to
MSB.
 If we do not have sufficient bits in grouping of 3-bits, we add
zeros to the left of MSB so that all the groups have proper 3-
bit number.
 Write the 3-bit binary number to its octal equivalent.

Use binary to decimal


conversion
Binary to Octal
 Convert 10000112 to Octal

Use binary to decimal


conversion
Binary to Octal (fraction)
 Break the fraction into 3-bit sections starting from MSB to
LSB.
 In order to get a complete grouping of 3 bits, we add
trailing zeros in LSB.
 Write the 3-bit binary number to its octal equivalent.

Use binary to decimal


conversion
Octal to Decimal
◦ Multiply each bit by 8n, where n is the “weight” of
the bit
◦ The weight is the position of the bit, starting from 0
on the right
◦ Add the results
Octal to Decimal

7248 => 4 x 80 = 4
2 x 81 = 16
7 x 82 = 448
46810
Octal to Decimal (fraction)
Hexadecimal to Decimal
◦ Multiply each bit by 16n, where n is the “weight” of
the bit
◦ The weight is the position of the bit, starting from
0 on the right
◦ Add the results
Hexadecimal to Decimal

ABC16 => C x 160 = 12 x 1 = 12


B x 161 = 11 x 16 = 176
A x 162 = 10 x 256 = 2560
274810
Hexadecimal to Decimal
Hexadecimal to Decimal (fraction)
Hexadecimal to Octal
 Combine all the binary numbers.
 Again group them into 3-bit form.
 Convert the 3-bit block in octal.

Use hexadecimal to
binary conversion

Use binary to decimal


conversion
Hexadecimal to Octal

Use hexadecimal to
binary conversion

Use binary to decimal


conversion
Hexadecimal to Octal (fraction)

Use hexadecimal to
binary conversion

Use binary to decimal


conversion
Exercises

 Convert into binary, octal and hexa


a) 2710
b) 1510
 Convert into decimal
a) 110112
b) 338
Compiler
Data Representation
 The way that the physical properties of a medium are
used to represent data.
 The manner in which data is expressed symbolically by
binary digits in a computer.
 How signs are represented in numerical values or how
strings are formatted (enclosed in quotes, terminated
with a null, etc.).
ASCII Code
ASCII is a 7 bit code which allows 128
characters
Extended ASCII allows 8 bits or 256
characters
Used to represent text although some
characters don’t print
0 – 31 are what is known as control
characters
Carriage Return, Tab, Clear Screen for
example
ASCII Code
65 in decimal = A
66 = B
67 = C and so on and so forth

Worksheet 2
UNICODE
What about the CODES that ASCII cannot
represent? The Japanese for example
UNICODE is a 16 bit code which is used to
represent a lot more characters

ASCII uses less memory (7 bits)


UNICODE capable of representing a lot
more characters
 Graphics are made up of tiny dots called
PIXELS each requiring one bit
 Picture Elements 49 bits memory. WHY?
Backing Storage Requirements
This image of screech measures 2 inches
by 2 inches.
It has a resolution of 80 dpi using 256
colours

Memory Required
Total Pixels
(2 * 80) * (2 * 80) = 25, 600
Each pixel could be one of 256 different
colours
256 requires 8 bits
25,600 * 8 = 204, 800 bits
204, 800 = 25,600 bytes or 25 kilobytes

You might also like