0% found this document useful (0 votes)
16 views136 pages

ch1-2 Updated

This document provides an introduction to computers and computing. It discusses that computers are used in many aspects of modern life from education and work to home use. It also describes that computers can be found in many devices beyond traditional personal computers. The document then defines that computers are programmed to perform tasks and that programmers write those programs. It also gives an overview of computer hardware components like the CPU, memory, storage, and input/output devices. Finally, it briefly discusses the history and evolution of computer science as a field.

Uploaded by

tabkhat.3alsari3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views136 pages

ch1-2 Updated

This document provides an introduction to computers and computing. It discusses that computers are used in many aspects of modern life from education and work to home use. It also describes that computers can be found in many devices beyond traditional personal computers. The document then defines that computers are programmed to perform tasks and that programmers write those programs. It also gives an overview of computer hardware components like the CPU, memory, storage, and input/output devices. Finally, it briefly discusses the history and evolution of computer science as a field.

Uploaded by

tabkhat.3alsari3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 136

I1100

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

• Devices that are computers…

– 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.

• it is a device that can be instructed to carry out an arbitrary set


of arithmetic or logical operations automatically.
• It follows a sequence of operations, called program
– A program is a set of instructions that a computer follows to perform a
task.

1-5
1.1 Introduction

• Programmers (Software Developers) are the


individuals that write programs.

• They have the training and skill to design,


develop, and test computer programs.

1-6
1.1 Programs Use

• Processing big amounts of Data


– Store/organize/retrieve
• Solving though Problems
– Complex computations
– Automated reasoning

1-7
Informatics – computer science

• It is the study of the structure, behavior, and


interactions of computational systems.

• As an academic field it involves the practice of


information processing, and the engineering
of information systems

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

The evolution of computer science can be divided into 5 generations.

1st generation (1945 – 1955): vacuum tubes (ENIAC (Electronic Numerical


Integrator and Computer) )
2nd generation (1955 – 1960): transistors (AT&T’s Bell Labs )
3rd generation (1960 – 1970): The integrated circuits (IC)
4th generation (1971+): Personal computers (PC) appeared as the result of the
microprocessor development (Intel, Apple Macintosh)
5th generation (early 90’s): Web, Laptop, GSM (Global System for Mobile
Communication), smartphones

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. the employee (CPU) moved to his desk


Input Processing Output
2. He is given files (input information)

3. It will return us the manipulated files


(information output)

Thus, we can consider the employee as a processing


system that delivers on the input information and
processes this information and restores us
1-12
In the example, there are 2 things:

- The Office Worker ó HARDWARE

- The instructions to be executed by the use (what is


asked) ó SOFTWARE (Big Programs)

1-13
1.2 Hardware and Software

Concept:

• The physical devices that a computer is made of are


referred to as the computer’s hardware.

• The programs that run on a computer are referred to as


software.

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

Central Processing Unit (CPU)

The CPU is the part of a computer that runs the


programs.

Running or executing a program is the term used


when the computer performs the tasks that the
program tells it to do.
Speeds now exceed 3 gigahertz (GHz)

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.

• The 1st computer monitors used cathode ray tubes (CRT)


• voluminous, heavy with high power consumption.

• The liquid crystal displays (LCD)


• low in power consumption, have a lighter weight and smaller physical size but has
higher price versus a CRT

1-26
Input and output devices
Modems; Network cards; Touch Screen, Headsets (Headset
consists of Speakers and Microphone) , ….

The modem (modulate demodulate) is used for sending and


receiving information and data over telephone lines. There are at
least 2 ways that can be used to represent data and information
electronically. One way is digital and another way is analogue.

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

• Everything a computer does is controlled by


software.
• 2 categories of software:
• System software
• Application 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

• All computers are based on the Von Neumann


Architecture : Model for designing and building
computers

1-36
The Von Neumann Architecture

based on the following 3 characteristics:


1) The computer consists of 4 main sub-systems:
1. Memory
2. ALU (Arithmetic/Logic Unit)

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.

• Memory Access Time (read from/ write to memory)


– 50-75 nanoseconds (1 nsec. = 10-9= 0.000000001 sec.)

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.

• Store (address, value):


– Store the specified value into the memory cell specified by
address.
– Destructive, overwrites the previous value of the 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, …

• Mass-Storage Device Access Methods:


– Direct Access Storage Devices (DASDs)
• Hard-drives, CD-ROMs, ...

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.

• A "head actuator" (something like an arm in a


relatively fixed position) records (writes) or reads
the information on the tracks.

• A hard disk/drive unit comes with a set rotation


speed ~ 7200 rpm (round per minute).
• Disk access time is measured in milliseconds (~
10msec. = 10,000,000 nsec ).

• Although the physical location can be identified


with cylinder, cluster, and sector

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:

All data that is stored in a computer is converted to


sequences of 0s and 1s.

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:

Determining the value of 10011101 The bit pattern for 157

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

Figure 1-12 Two bytes used for a large number

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

The letter A is stored in memory as the number 65

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

- Integer part - Integer part - Integer part


Example
convert the fraction 0.875 to binary
Solution
Example
convert the fraction 0.875 to binary
Solution
Multiply the number continuously by 2 and
extract the integer part as the binary digit. Stop
when the number is 0.0.
Example
Transform the fraction 0.4 to a binary of 6 bits.
Solution
Multiply the number continuously by 2 and
extract the integer part as the binary digit. You
can never get the exact binary representation.
Stop when you have 6 bits.

0.4 è 0.8 è 1.6 è 1.2 è 0.4 è 0.8 è 1.6


0 . 0 1 1 0 0 1
Example

Store 7 in an 8-bit memory location.

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

Store 258 in a 16-bit memory location.

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

• Finally the conversion is:


– (28.8625)10 = (11100. 11011100 … )2
Conversion form decimal base

• A repeated division and remainder


algorithm can convert decimal to binary,
octal, or hexadecimal.
• Divide the decimal number by the desired
target radix (2, 8, 16, …. ).
• Append the remainder as the next most
significant digit.
• Repeat until the decimal number has reached
zero.
Binary (b=2) ÞDecimal (b=10)
An integer N is written in binary an an-1 …a1 a0 where ai=0
or 1, we will convert it to decimal
N= an 2n + an-1 2n-1 + …. + a0 20
Add the digits to get the decimal representation.

Binary (b=2) Þ Octal (b=8)


Let N = (111010100011101)2

We divided this series of 0 and 1 in sets of 3 bits, each set of


3 bits is a number in the base 8:

Then N = (111 010 100 011 101)2 = (7 2 4 3 5)8

1-86
Binairy (b=2) Þ Hexadecimal (b=16)
Let N = ( 111010100011101)2

We divided this series of 0 and 1 in sets of 4 bits, each


set of 4 bits is a number in the base 16:

N= (0111 0101 0001 1101)2 = ( 751D)16

We can add 0¢s to the left of the binary number to be


divisible in groups of 3 or 4 bits

1-87
Ex: Converting Binary to Octal

• Mark groups of three (from right)


• Convert each group

10101011 10 101 011


2 5 3

10101011 is 253 in base 8

88
17
Ex: Converting Binary to
Hexadecimal
• Mark groups of four (from right)
• Convert each group

10101011 1010 1011


A B

10101011 is AB in base 16

89
18
Octal to Decimal conv

What is the decimal equivalent of the octal


number 642?

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

What is the decimal equivalent of the


hexadecimal number DEF?

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

Remember, the digits in base 16 are


0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
93
Decimal to hexadecimal

Convert (2607.565 )10 = (???)16


Start with the integer part :

Quotient Remainder Coefficient


(2607)10 / 16 162 15 (F) a0
162/16 10 2 a1
10/16 10 (A) a2

(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.

Store +7 in an 8-bit memory location using sign-and-magnitude


representation.
1. First change the number to binary 111.
2. Add four 0s to make a total of N-1 (7) bits, 0000111.
3. Add an extra zero because the number is positive. The result
is: 00000111
Example

Store –258 in a 16-bit memory location


using sign-and-magnitude representation.
Solution
1. First change the number to binary 100000010.
2. Add six 0s to make a total of N-1 (15) bits, 000000100000010.
3. Left most bit is 1 because the number is negative. The result is:
1000000100000010
Example

Interpret 10111011 in decimal if the number


was stored as a sign-and-magnitude integer.

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:

There are two 0s in sign-and-magnitude


representation: positive and negative.
In an 8-bit allocation:
+0 è 00000000
-0 è 10000000
1'S COMPLEMENT AND 2'S
COMPLEMENT
One’s complement and two’s complement are two important binary
concepts.
2’s complement is especially important because it allows us to represent
signed numbers in binary, and 1’s complement is the interim step to
finding the 2’s complement.
Note:

• In 1’s complement 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.
1’s complement

ØIf the sign is positive (0), no more action is


needed;
ØIf the sign is negative, every bit is complemented
means reversing all bits.
Example

Store +7 in an 8-bit memory location using


1’s complement representation.
Solution
First change the number to binary 111.
Add five 0s to make a total of N (8) bits, 00000111.
The sign is positive, so no more action is needed.
The result is:
00000111
Example

Store –258 in a 16-bit memory location


using one’s complement representation.
Solution
• First convert the number to binary 100000010.
• Add seven 0s to make a total of N (16) bits,
0000000100000010
• The sign is negative, so each bit is complemented. The result is:
1111111011111101
Example

Interpret 11110110 in decimal if the number


was stored as a 1’s complement integer.
Solution
1. The leftmost bit is 1, so the number is negative.
2. First complement it : 00001001.
3. The complement in decimal is 9.
4. So the original number is –9.
Note that complement of a complement is the original number.
Examples of 8-bit one's
complement numbers:

there are different representations for +0 and -0


in one's complement!!!!
2's complement (the most common, the most important, and the most widely
used representation of integers today).

To get the 2's complement negative notation of


an integer,
1. write out the number in binary(If the sign is
positive, no further action is needed;)
2. If the sign is negative:
1. invert the digits, and
2. add one to the result.
Example:
Suppose we're working with 8 bits (for simplicity's sake) and
suppose we want to find how -28 would be expressed in 2's
complement notation.
1. First we write out 28 in binary form. 00011100
2. Then we invert the digits. 11100011
3. Then we add 1. + 1
4. Result: 11100100
That is how one would write -28 in 8 bit binary.
Note:

In 2’s complement 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.
There is only one 0 in 2’s complement:
In an 8-bit allocation:
0 è 00000000
Example

Store +7 in an 8-bit memory location using


2’s complement representation.
Solution
First change the number to binary 111. Add five
0s to make a total of N (8) bits, 00000111.
The sign is positive, so no more action is needed.
The result is:
00000111
Example
Store –40 in a 16-bit memory location using 2’s
complement representation.
Solution
1. First change the number to binary 101000.
2. Add ten 0s to make a total of N (16) bits,
0000000000101000.
3. invert: 1111111111010111.
4. add 1: 1111111111011000
0 in 2’s complement

Assuming you are representing 0 as one byte .i.e 0 = (00000000)2

one's complement = (11111111)2

2's complement = 1's complement +1 = (11111111)2 +1 = (00000000)2


We can have 2 representation of 0 in one's complement. That’s why people
and most of architectures prefer 2's complement.
Examples of 8-bit 2's complement
numbers:
Binary octal hexadecimal

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.

– The last expression is correctly normalized.


Floating-Point
Representation

• Another problem with our system is that we have


made no allowances for negative exponents. We
have no way to express 0.5 (=2 -1)! (Notice that
there is no sign in the exponent field.)

All of these problems can be fixed with no


changes to our basic model.
Floating-Point
Representation
• To provide for negative exponents, we will use a biased exponent.
• A bias is a number that is approximately midway in the range of
values expressible by the exponent.
• We add the bias from the value in the exponent to determine its true
value.
– In our case, we have a 5-bit exponent (32/2=16).
– We will use 16 for our bias. This is called excess-16 representation.

• In our model, exponent values less than 16 are negative,


representing fractional numbers.
Example 1 Sign
0(+) or
1(-)
Power of 2
5 bits
Significand

• 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)

• Ex: if we use 40.000 samples per second and 16


bits per each sample, the bit rate R= S*B=
40.000*16=640.000 bits per second =
640kilobits Per Second
1-155
1-156
Storing images
• Images are stored in computers using 2
different techniques:
– Raster/bitmap images,
– vector images (we will not describe it)

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

• fast small memory.


• Used as a buffer between the CPU and main memory.
• Minimizes CPU access time to the main 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)

• Volatil memory loses its contents when the power is


turned off.
• contains:
• the program for a specific treatment,
• the data it requires and the results it generates

166
RAM (Random Access Memory)

2 technologies static and dynamic RAM:


SRAM (Static RAM) and DRAM (Dynamic RAM) holds data
but in a different ways.
DRAM requires the data to be refreshed periodically in
order to retain the data.
SRAM does not need to be refreshed as the transistors
inside would continue to hold the data as long as the
power supply is not cut off. SRAM faster than DRAM.

167
ROM (Read Only Memory)

• ROM is "built-in" computer memory containing data that normally can


only be read, not written to. ROM contains the programming that allows
your computer to be "booted up" or regenerated each time you turn it
on. Unlike a computer's random access memory (RAM), the data in ROM
is not lost when the computer power is turned off. The ROM is sustained
by a small long-life battery in your computer.
• If you ever do the hardware setup procedure with your computer, you
effectively will be writing to ROM.

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.

• The difference between a PROM and a ROM (read-only memory) is


that a PROM is manufactured as blank memory, whereas a ROM
is programmed during the manufacturing process.
• To write data onto a PROM chip, you need a special device called
a PROM programmer or PROM burner. The process of
programming a PROM is sometimes called burning the PROM

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

You might also like