ch1-2 Updated
ch1-2 Updated
Introduction to computing
Computer Science department
Introduction to Computers and Programming
1.1 Introduction
• People use computers at…
– School for writing papers, research, email, online classes,
etc.
– Work for analyzing data, make presentations, business
transactions, communicating, control machines, etc.
– Home for paying bills, shopping online, communicating,
playing computer games, etc.
1-3
1.1 Introduction
– Calculators
– Cell/Smart Phones
– MP3/DVD Players
– Car navigation system (GPS)
– …..
1-4
1.1 Introduction
Computers are designed to do any job that their programs tell
them to do.
1-5
1.1 Introduction
1-6
1.1 Programs Use
1-7
Informatics – computer science
1-8
Jobs in Computer Science
• Database administrator
• Network administrator
• Network architect
• Software project manager/ IT project manager
• Computer programmer
• Mobile application developer
• Computer security expert
• Computer instructor
• Industrial computer scientist
• System engineer
• Telecommunications network engineer
• Computer maintenance technician
• Software tester
1-9
History of Computer Science
1-10
HARDWARE && SOFTWARE
1-11
1.1 In few words…
To understand how a computer works, we
will make an analogy with the way an
office worker does.
1-13
1.2 Hardware and Software
Concept:
1-14
1.2 Hardware
Typical components of a computer system:
– Central Processing Unit (CPU)
– Main memory
– Secondary storage
– Input devices
– Output devices
1-15
1.2 Hardware
1-16
clock
speed(ghz) refers to
the number of pulses
per second generated
by an oscillator that
sets the tempo for
the processor.
1-17
1.2 Hardware
(courtesy of U.S. Army Historic Computer Images)
CPU
ENIAC(Electronic Numerical
Integrator And Computer)
• World’s 1st programmable computer
(1945)
• Designed for the U.S. Army
• CPU was 2.5 m tall, and weighed 30
tons
Microprocessor (1968)
• Much smaller
• Much more powerful
1-18
1.2 Hardware
Main Memory
• Stores the program that is running as well as the data
• Commonly known as the Random-Access Memory
(RAM)
– Data is quickly accessed
– a RAM chip is volatile and requires a constant source of power
to retain information. When power is lost or turned off, a RAM
chip will lose the information stored on it.
– Used for temporary storage
For example, the Internet browser you use to read a web page is 1st loaded into
memory and is running from memory
1-19
What is the difference between ROM and
RAM?
• A ROM (Read Only Memory) is non-volatile storage and does not require a constant
source of power to retain information stored on it. When power is lost or turned off, a
ROM will keep the information stored on it.
example BIOS (Basic Input/Output System) chip stores the programming needed to
begin the initial computer start up process.
1-20
RAM ROM
Random Access Memory is a form Read-only memory is also a form of
Definition of data storage that can be data storage that can not be easily
accessed randomly at any time, in altered or reprogrammed. Stores
any order and from any physical instructions that are necessary for
location., allowing quick access re-booting up to make the computer
and manipulation. operate when it is switched off.
Use RAM allows the computer to ROM stores the program required
read data quickly to run to initially boot the computer. It only
applications. It allows reading and allows reading.
writing.
Volatility RAM is volatile i.e. its contents are It is non-volatile i.e. its contents are
lost when the device is powered retained even when the device is
off. powered off.
Types The two main types of RAM are The types of ROM include PROM,
static RAM and dynamic RAM. EPROM and EEPROM.
1-21
1.2 Hardware
Secondary Storage Devices
• can hold data for long periods of time.
• Hard Disk Drive : is a data storage device used for storing and
retrieving digital information
• USB drives
• Optical devices (CD or DVD)
• SD-cards
• Flash memory
• ……
1-22
1.2 Hardware
Input Devices
• Any data the computer collects from people and from other devices
is called input.
• The hardware component that collects the data is called an input
device.
• Common input devices are:
– Keyboard (QUERTY and AZERTY)
– Mouse
– Scanner
– Microphone
– Digital camera
1-23
1.2 Hardware
Output Devices
• Any data the computer produces for people or for other devices is called
output.
• The hardware component that formats and presents the data is called an
output device.
• Common output devices are:
– monitor
– Printer
– LCD Projection Panels.
– Speaker(s)
– Head Phone
– …..
1-24
Monitor
The display resolution or display modes is the
number of distinct pixels in each dimension that
can be displayed.
It is usually quoted as width × height, with the
units in pixels:
for example, "1024 × 768" means the width is
1024 pixels and the height is 768 pixels.
1-25
Monitors are connected to the computer via different types of
connectors like:
VGA (Video Graphics Array),
DVI (Digital Visual Interface), and
HDMI (High-Definition Multimedia Interface) connectors.
1-26
Input and output devices
Modems; Network cards; Touch Screen, Headsets (Headset
consists of Speakers and Microphone) , ….
1-28
Cards
• Cards are components added to computers to
increase their capability.
• When adding a peripheral device make sure that
your computer has a slot of the type needed by
the device.
1-29
Cards
• Sound cards allow computers to produce sound
like music and voice.
• Graphic cards allow computers to produce
color (with a color monitor of course) -- EGA
and VGA (Video Graphics Array)
• Video cards allow computers to display video,
animation , and television
• Network cards allow computers to connect
together to communicate with each other.
1-30
motherboard
• is the main circuit board in a computer.
• It connects all the different components of the computer such as CPU,
memory, connectors for input and output devices, and allows communication
between them
Parts of a Motherboard (principal parts)
CPU socket
Power connector
Slots (main memory, hard drives, video, PCI (Peripheral Component Interconnect) …)
ROM (BIOS)
…
1-31
1.2 Software
1-32
1.2 Software
System Software
• Programs that control and manage the basic
operations of a computer are referred to as
Operating System (OS).
• Windows, Linux, Mac-OS, Android, iOS, Symbian…
1-33
1.2 Software
Application Software
• is a program or group of programs designed to perform a
group of coordinated functions, tasks, or activities for the
benefit of the user
• For example:
• Word processing
• Database
• Presentation
• Internet Surfing: web browser
• ……
1-34
The Von Neumann Architecture
Von Neumann
Architecture
Designing Computers
1-36
The Von Neumann Architecture
CPU
3. Control Unit
4. Input/Output System (I/O)
2) Program is stored in memory during execution.
3) Program instructions are executed sequentially.
1-37
The Von Neumann Architecture
Bus
Processor (CPU)
Memory Input-Output
Control Unit
ALU
Store data and program Communicate with
"outside world", e.g.
• Screen
Execute program
• Keyboard
Do arithmetic/logic operations • Storage devices
requested by program • ...
38
Memory Size / Speed
The bit is a basic unit of information in computing and digital
communications. A bit can have only one of two values, and may therefore be
physically implemented with a two-state device.
• Typical memory in a personal computer (PC) of RAM: 64MB - 256MB
• Memory sizes:
– 1 Byte = 8 bits.
– 1 Kilobyte = 1 KB = 210 B = 1,024 Byte.
– 1 Megabyte = 1 MB = 210 KB = 220 Byte.
– 1 Gigabyte = 1 GB = 210 MB = 230 Byte.
– 1 Terabyte = 1 TB = 210 GB = 240 Byte.
– 1 Petabyte = 1 PB = 210 TB = 250 Byte,
– 1 Exabyte = 1 EB = 210 PB
– 1 Zettabyte = 1 ZB = 210 EB,
– 1 Yottabyte = 1 YB = 210 ZB.
1-40
Operations on Memory
• Fetch (address):
– Fetch a copy of the content of memory cell with the specified
address.
– Non-destructive, copies value in memory cell.
1-41
Input/Output Subsystem
• Handles devices that allow the computer system to:
– Communicate and interact with the outside world
• Screen, keyboard, printer, ...
– Store information (mass-storage)
• Hard-drives, CD, flash memories, …
1-42
Hard disk
• A hard disk is a set of stacked "disks," each of
which, has data recorded in concentric circles or
"tracks" on the disk.
1-43
How Data is Organized on Disk
• Tracks-
– circular areas of the disk
• Sectors-
– Divides tracks sections
– Can store 512 bytes = 29 bytes
• Clusters-
– Groups of sectors used by OS (operating system)
– 64 sectors in one cluster
1-44
I/O Controllers
• Speed of I/O devices is slow compared to RAM
– RAM ~ 50 nsec.
– Hard-Drive ~ 10,000,000 nsec
• Solution:
– I/O Controller, a special processor:
• Has a small memory buffer, and a control logic to
control I/O device (e.g. move disk arm).
• Sends an interrupt signal to CPU when done read/write.
– Data transferred between RAM and memory buffer.
– Processor free to do something else while I/O controller
reads/writes data from/to device into I/O buffer.
1-46
The ALU Subsystem
• The ALU (Arithmetic/Logic Unit) performs
– mathematical operations (+, -, *, /, …)
– logic operations (=, <, >, and, or, not, ...)
• In today's computers integrated into the CPU
• Consists of:
– Circuits to do the arithmetic/logic operations.
– Registers (fast storage units) to store intermediate
computational results.
– Bus that connects the two.
1-48
Structure of the ALU
• Registers:
– Very fast local memory cells, that store R0
operands of operations and intermediate R1
results.
R2
• ALU circuitry:
– Contains an array of circuits to do
mathematical/logic operations.
– CCR (condition code register), a special Rn
purpose register that stores the result of
<, = , > operations
ALU circuitry
• Bus:
– Data path interconnecting the registers
to the ALU circuitry. CCR GT EQ LT
49
The Control Unit (Fetch-Decode-
Execute)
• Program is stored in memory
– as machine language instructions, in binary
• The task of the control unit is to execute programs by
repeatedly:
1. Fetch (address)from memory the next instruction to be
executed.
2. Decode it, that is, determine what is to be done.
3. Execute it by sending the appropriate signals to the ALU,
memory, and I/O subsystems.
4. Continues until the HALT instruction
1-50
Machine Language Instructions
• A machine language instruction consists of:
– Operation code, telling which operation to perform
– Address field(s), telling the memory addresses of the
values on which the operation works.
• Example: ADD X, Y (Add content of memory locations
X and Y, and store back in memory location Y).
• assume:
– opcode for ADD is 9, and
– addresses X is 99,
– Y is 100 (we will see later binary language)
Opcode (8 bits) Address 1 (16 bits) Address 2 (16 bits)
00001001 0000000001100011 0000000001100100
1-51
INFORMATION
REPRESENTATION
1-52
1.3 How Computers Store Data
Concept:
1-53
1.3 How Computers Store Data
• A computer’s memory is divided into tiny storage locations
known as bytes
• A byte is divided into 8 smaller storage locations known as bits
(binary digits)
• Bits are electrical components that can hold either a positive (1
== 5 volts) or a negative charge (0 == 3 volts).
1-54
Conversion units
• 1 Bit = 0 or 1
• 1 Byte = 23 = 8 Bits
• 1 KB(kilo Byte) = 210 Bytes = 1024 Bytes
• 1 MB (Mega Byte) = 220 Bytes
• 1 GB(Gega Byte) = 230 Bytes
• 1 TB (Tera Byte) = 240 Bytes
1-55
1.3 How Computers Store Data
Storing Numbers
• This corresponds to the binary numbering system (base 2)
where all numeric values are written as a sequence of 0s and 1s
• Each digit in a binary number has a value assigned to it
1-56
1.3 How Computers Store Data
Storing Numbers
For example:
1-57
1.3 How Computers Store Data
Storing Numbers
• The largest value that can be stored in a byte (8 bits) is 255
• 2 bytes are used for larger numbers; maximum value is
65535
1-58
1.3 How Computers Store Data
Storing Characters
• Characters are stored in the computer’s memory as binary
number
• ASCII (American Standard Code for Information
Interchange) is a coding scheme
0 1 0 0 0 0 0 1
3v 5v 3v 3v 3v 3v 3v 5v
1-59
1.3 How Computers Store Data
Storing Characters
• ASCII stands for American Standard Code for
Information Interchange: is a set of 128 numeric
codes
• ASCII is limited
• Unicode is an extensive encoding scheme
• It is compatible with ASCII
• It represents characters for many languages in
the world
1-60
Example:
ACII(A ) = (65)10 = ( 0100 0001)2
ACII(B ) = (66)10 = ( 0100 0010)2
ACII(C ) = (67)10 = ( 0100 0011)2
1-61
1-62
Number
Representation
Decimal Binary Octal (8) Hexadecimal (16)
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
16 10000 20 10
Decimal system
Binary system
Binary to decimal conversion
Decimal to Binary conversion
Example
Convert the binary number 10011 to decimal.
Solution
Example
Convert the binary number 10011 to decimal.
Solution
Write out the bits and their weights. Multiply the bit by
its corresponding weight and record the result. At the
end, add the results to get the decimal number.
Binary 1 0 0 1 1
Weights 16 8 4 2 1
-------------------------------------
16 + 0 + 0 + 2 + 1
Decimal 19
Example
Convert the decimal number 35 to binary.
Solution
Example
Convert the decimal number 35 to binary.
Solution
Number /2 Remainder
35 17 1
17 8 1
8 4 0
4 2 0
2 1 0
/2 /2
1
Binary 1 0 0 0 1 1
converting fractions to binary
Multiply the number continuously by 2
and extract the integer part as the binary
digit. Stop when the number is 0.0.
*2 *2 *2
Solution
First change the number to binary 111. Add five
0s to make a total of N (8) bits, 00000111. The
number is stored in the memory location.
Example
Solution
First change the number to binary 100000010.
Add seven 0s to make a total of N (16) bits,
0000000100000010. The number is stored in the
memory location.
Exercise
Convert (28.8625)10 to binary -- the fractional part is coded on 8 bits
We will start with factional part:
• 0.8625*2= 1.725= 1 + 0.725
• 0.725*2= 1.45 = 1 + 0.45
• 0.45*2= 0.9 = 0 + 0.9
• 0.9*2= 1.8= 1+ 0.8
• 0.8*2= 1.6= 1+ 0.6
• 0.6*2= 1.2 = 1+ 0.2
• 0.2*2= 0.4 = 0+ 0.4
• 0.4*2= 0.8 = 0 + 0.8
• We will convert the integer part now:
(28)10 = (11100) 2
1-86
Binairy (b=2) Þ Hexadecimal (b=16)
Let N = ( 111010100011101)2
1-87
Ex: Converting Binary to Octal
88
17
Ex: Converting Binary to
Hexadecimal
• Mark groups of four (from right)
• Convert each group
10101011 is AB in base 16
89
18
Octal to Decimal conv
2 x 8º = 2 x 1 = 2
+ 4 x 81 = 4 x 8 = 32
+ 6 x 82 = 6 x 64 = 384
= 418 in base 10
92
11
Hexadecimal to Decimal conv
F x 16º = 15 x 1 = 15
+ E x 161 = 14 x 16 = 224
+ D x 162 = 13 x 256 = 3328
= 3567 in base 10
(2607)10 = (A2F)16
Fractional part conv on 7 bits only
Signed number representation
16/10
Signed integers
In sign-and-magnitude representation, the leftmost bit defines
the sign of the number.
If it is 0, the number is positive.
If it is 1, the number is negative.
Solution
1. Ignoring the leftmost bit, the remaining bits are 0111011.
2. This number in decimal is 59.
3. The leftmost bit is 1, so the number is –59.
Note:
ADDITION AND
SUBTRACTION
Binary Addition
Rules.
– 0+0=0
– 0+1=1
– 1+0=1
– 1 + 1 = 2 = 102 = 0 with 1 to carry
– 1 + 1 + 1 = 3 = 112 = 1 with 1 to carry
1-135
Adding Binary Numbers (cont.)
1 1
0+0=0
1 01
0+1= 1
+ 1 1 1
1+0= 1
_______________
1 + 1 = 10
11 00
Carry Values
111111
1010111
+1 0 0 1 0 1 1
10100010
Floating-Point
Representation
• They are often expressed in scientific notation (has
a single 0 digit to the left of the decimal point).
– example: 0.125 = 1.25 ´ 10-1
Floating-Point
Representation
• Example:
– Express 3210 in the simplified 14-bit floating-point model (1 bit for sign; 5
bits for 2 power; 8 bits for fractional part ).
• We know that 32 is 25. So in (binary) scientific notation
– 32 = 1.0 x 25 = 0.1 x 26. (normalized 0.1……. . )
• Using this information, we put 110 (= 610) in the exponent field and 1 in the
significand as shown.
Power of 2 Significand : Fractional binary
is 6 .1
Floating-Point
Representation
• the 1st digit of the significand must be 1, with no ones to
the left of the radix point.
• This process, called normalization, results in a unique pattern
for each floating-point number.
– In our simple model, all significands must have the form
0.1xxxxxxxx
– For ex, 4.5 = 100.1 x 20 = 1.001 x 22 = 0.1001 x 23.
• Example:
– Express 3210 in the revised 14-bit floating-point
model.
• We know that 32 = 0.1 x 26.
• To use our excess 16 biased exponent, 6 + 16 = 2210
(=101102).
• So we have:
6+ 16 = 22
+ Power of 2
Example 2 Sign
0(+) or
1(-)
Power of 2
5 bits
0.Significand
• Example:
– Express 0.062510 in the revised 14-bit floating-
point model.
• We know that 0.0625 is 2-4.
• So in (binary) scientific notation
0.0625 = 0.1 x 2 -3.
• To use our excess 16 biased exponent, we add 16 to -3,
giving 1310 (=011012).
-3+ 16=13
Example 3
• Example:
– Express -26.62510 in the revised 14-bit floating-
point model.
• We find 26.62510 = 11010.1012.
• Normalizing, we have: 26.62510 = 0.11010101 x 2 5.
• To use our excess 16 biased exponent, we add 16 to
5, giving 2110 (=101012). We also need a 1 in the sign
bit.
- 5+ 16 = 21 0.11010101
Storing texts
• We represent each symbol with a bit pattern
• Example:
• A: 1000001 (65)10
• B: 1000010 (66)10
• C: 1000011 (67)10
How many bits are needed in a bit-pattern to represent a symbol in
a language?
It depends on the nber of symbols in that language
The relation is logarithmic
If we need 2 symbols the length is 1 bit (log22= 1)
If we need 4 symbols the length is 2 bit (log24= 2)
1-152
1-153
1-154
Storing audio
• Bit depth (B) : nber of bits allocated for each
sample (nowadays 16 bits or 32 bits)
• Bit rate: we need to store S*B for each second
of audio (S : nber of samples per second)
1-157
1-158
1-159
1-160
Storing video
• Video is a representation of images (called frames) over time
• Movie: series of frames shown one after another to create the illusion of
motion
• Video: representation of information that changes in space (single image)
and in time (a series of images)
• Each image or frame is transformed into a set of bit patterns and stored.
• The combination represents the video
• Today video is normally compressed
• Ex: Mpeg is a common video compression technique
1-161
Memory
A device that can save, store and retrieve
information.
The different memory elements are ordered
according to the following criteria: access
time, capacity and cost.
When you move away from CPU to secondary
memory, we find that the access time and
capacity of memory increases and the cost
per bit decreases.
162
Registers
• The processor uses registers
• small internal memory very fast access
• used to temporarily store some information.
• The number of registers depends on the processor type.
• Example of registers:
• MAR(Memory Address Register)
• Memory Buffer Register (MBR)
• I/O Address Register (I/O AR)
• I/O Buffer Register (I/O I3R)
• Accumulator Register
• Program Counter (PC)
• ……
163
Cache memory
164
Central memory/ main
memory
• The main storage of information used by the CPU.
• access time is much greater than to registers and
cache memory.
• Any program to run must be loaded in main memory.
• The CPU looks for instructions one after the other
to run sequentially.
• The capacity and speed of the main memory are key
elements in the power of a computer.
• Two types: RAM and ROM.
165
RAM (Random Access Memory)
166
RAM (Random Access Memory)
167
ROM (Read Only Memory)
168
ROM (Read Only Memory)
• PROM - (programmable read-only memory) is a memory chip on
which data can be written only once. Once a program has been
written onto a PROM, it remains there forever.
169
EPROM, EEPROM
• EPROM - (erasable programmable read-
only memory) is a special type of PROM
that can be erased by exposing it to
ultraviolet light. Once it is erased, it
can be reprogrammed.
• An EEPROM is similar to a PROM, but
requires only electricity to be erased.
170
Secondary / mass memory
• high capacity and relatively low cost.
• They serve as permanent storage elements and
use it to magnetic media (disks) and optical
media (CD-ROM, CD-RW, DVD-ROM ...)
171