0% found this document useful (0 votes)
4 views102 pages

103 Introduction

The document introduces the concept of computers, outlining three models: Data Processor, Turing Model, and Von-Neumann Model, each with distinct characteristics regarding data processing and program execution. It discusses the evolution of numbering systems from non-positional to positional, emphasizing the importance of understanding different bases like decimal, binary, octal, and hexadecimal. Additionally, it touches on social and ethical issues related to computers, such as privacy and digital divide.

Uploaded by

muhammad saad
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)
4 views102 pages

103 Introduction

The document introduces the concept of computers, outlining three models: Data Processor, Turing Model, and Von-Neumann Model, each with distinct characteristics regarding data processing and program execution. It discusses the evolution of numbering systems from non-positional to positional, emphasizing the importance of understanding different bases like decimal, binary, octal, and hexadecimal. Additionally, it touches on social and ethical issues related to computers, such as privacy and digital divide.

Uploaded by

muhammad saad
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

Chapter 1: Introduction

What is a Computer?

Model 1: Data Processor "Special Purpose" Model 3: Von-​Neuman "General Purpose"


‫معالج بيانات‬ Model 2: Turing Model "General Purpose"
Model 1: Data Processor "Special Purpose"
‫معالج بيانات‬

Input Output

5+9 Input Output 14


Chapter 1: Introduction

What is a Computer?

Model 2: Turing Model "General Purpose"

Program

Input Output

Program

5+9 Input Output 14

Any Program

Universal
Input Turing Output
Machine

In Turing Model:
Universal Turing Machine:
Input/Output Data are stored in Memory. could calculate any formula that could be formulated.

Programs are implemented on Electrical Circuits and


managed by Electrical Engineers or Technicians.

!
g Machine
e of a Turin
urate pictur
A more acc

Do you think a Universal Turing Machine exists?


Model 3: Von-​Neuman "General Purpose"

Hardware Software Data

ALU Control Unit Memory Input/Output


Operating System, OS Applications, APPs Input Output
Systems

Sequential execution of code (We will see the details in Chapter 5)

In Von Neuman Model:

Input/Output Data are stored in Memory.

Programs are stored in Memory and coded by


programmers.

Hence ... both Data and Programs should have the same
format: a sequence of 0s and 1s (like 01010101101)
Do you think a Universal Turing Machine exists?

NP Hard Problems

Should Compute all possible


steps to know the best path
Could use some
tricks to reduce
the search

Could use
Distributed
computing "On
the Cloud"

Privacy
Isuues!!
Issues Related to Computers

Social Issues Ethical issues

Dependency Social Justice Digital Divide Privacy Copyrights Computer Crime


Chapter 2: Number Systems
‫أنظمة الترقيم‬

Since Pre-​History, humans used to count from 1 to 10,

... Probably because they have 10 Fingers in their


hands!

BUT
As human needs grow, they invented other numbering systems as well

Numbering Systems
Not in the
Exam! Non-​Positional Positional
The position of the number is not important The position of the number is important

Example: 12 is not the same as 21


Example: In Roman Numbering System:
IV is the same as VI (V = 5; I = 1)
Positional Numbering Systems

Decimal Binary Octal Hexadecimal


‫النظام العشري‬ ‫النظام الثنائي‬ ‫النظام الثماني‬ ١٦ ‫النظام الستاعشري‬
10,11,12,13,14,15
Set of symbols, S = {0,1,2,3,4,5,6,7,8,9} Set of symbols, S = {0,1} Set of symbols, S = {0,1،2,3,4,5,6,7} Set of symbols, S = {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}

Thousands Hundreds Tens Ones ___ _______ __________ _____ _____ ____________ __________ _____ _____ ____________ __________ _____ _____

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 0 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 0 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 0 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 0

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 1 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 1 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 1 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 1

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 2 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 0 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 2 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 2

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 3 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 1 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 3 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 3

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 4 ​ ​ ​0 ​ ​ ​ ​ 1 ​ ​ ​0 ​ ​ 0 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 4 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 4

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 5 ​ ​ ​0 ​ ​ ​ ​ 1 ​ ​ ​0 ​ ​ 1 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 5 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 5

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 6 ​ ​ ​0 ​ ​ ​ ​ 1 ​ ​ ​1 ​ ​ 0 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 6 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 6

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 7 ​ ​ ​0 ​ ​ ​ ​ 1 ​ ​ ​1 ​ ​ 1 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 7 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 7

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 8 ​ ​ ​1 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 0 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 0 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 8

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 9 ​ ​ ​1 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 1 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 1 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 9

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 0 ​ ​ ​1 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 0 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 2 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ A

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 1 ​ ​ ​1 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 1 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 3 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ B

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 2 ​ ​ ​1 ​ ​ ​ ​ 1 ​ ​ ​0 ​ ​ 0 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ C
​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 4

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 3 ​ ​ ​1 ​ ​ ​ ​ 1 ​ ​ ​0 ​ ​ 1 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ D
​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 5

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 4 ​ ​ ​1 ​ ​ ​ ​ 1 ​ ​ ​1 ​ ​ 0 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 6 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ E

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 5 ​ ​ ​1 ​ ​ ​ ​ 1 ​ ​ ​1 ​ ​ 1 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ F
​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 7

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 6 1 ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 0 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 0
​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​2 ​ ​ 0
But HOW can we know if 11 is in Decimal or Binary or Octal or Hexadecimal?!

By default, the number is assumed to be in Decimal


Or, we could use the following notation:
(11) means the base is Decimal
10
(11) 2 means the base is Binary
(11) 8 means the base is Octal
(11)16 means the base is Hexadecimal

But HOW can we know the number of digits (binary or octal or hexadecimal) we need to
convert a Decimal number?

We use the following formula:

Without Counting the number Zero 0


Number of Digits
Maximum number supported by given digits = (Base)

With Counting the number Zero 0 Number of Digits


Maximum number supported by given digits = (Base) ​ ​ ​ ​ ​ ​- ​1

Example: Exercise:

What is the required number of binary digits needed to store (30) 10 ? What is the required number of Octal digits needed to store (30)10 ?

digits 0 0
max number = (base) -1 2 = 1 2 -1= 0
1
digits
2 = 2 1
2 -1= 1
2
max number = (2) -1 2 = 4 2
2 -1= 3 Smaller than
30

23 = 8 3
2 -1= 7
5
max number = (2) - 1 = 31 24 = 16 24 - 1 = 15
25 = 32 5
2 -1= 31 Big Enough to
store 30

26 = 64 6
2 -1= 63
Answer = 5 7 7
2 = 128 2 -1= 127
8 8
2 = 256 2 -1= 255
29 = 512 9
2 -1= 511
10 10
2 = 1024 2 -1= 1023
Binary, base 2

Converting Decimal to Octal, base 8 using Long Division

Hexadecimal, Base 16

Decimal to Binary Decimal to Octal Decimal to Hexa

Convert (30)10 to Binary Convert (30)10 to Octal Convert (30) 10 to Hexadecimal

0 1 3 7 15 30 0 3 30 0 1 30

1 1 1 1 0 3 6 1 E

Exercise: Convert (70) to Binary Exercise: Convert (70) to Octal Exercise: Convert (70) to Hexadecimal
10 10 10

70 70
70

? ? ? ?
0 1 2 4 8 17 35 70
0 4 70
0 1 8 70

1 0 0 0 1 1 0
4 6
1 0 6
Converting

Decimal, base 10 Binary, base 2

x
using Exponent Method (2 )

x
In Decimal In (2 ) In Binary

0
1 2 0 ​ ​ 0
​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 1

1
2 2 0 ​ ​ 0
​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 0

2
4 2 0 ​ ​ 0
​ ​ ​ ​ 1 ​ ​ ​0 ​ ​ 0

3
8 2 0 ​ ​ 1
​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 0

4
16 2 1 ​ ​ ​0 ​ ​ ​ 0 ​ ​ ​0 ​ ​ 0

Using this pattern, we can use the following notation:


Binary 0 ​ ​ 0
​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 1
4 3 2 1 0
2 2 2 2 2
16 8 4 2 1
Decimal ( 0 * 16) + (0 * 8) + (0 * 4) + (0 * 2) + (1 * 1) = 1

Binary
0 ​ ​ 0
​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 0

4 3 2 1 0
2 2 2 2 2
16 8 4 2 1
Decimal ( 0 * 16) + (0 * 8) + (0 * 4) + (1 * 2) + (0 * 1) = 2

Binary 0 ​ ​ 0
​ ​ ​ ​ 1 ​ ​ ​0 ​ ​ 0
4 3 2 1 0
2 2 2 2 2
16 8 4 2 1
Decimal ( 0 * 16) + (0 * 8) + (1 * 4) + (0 * 2) + (0 * 1) = 4

Binary 0 ​ ​ 1
​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 0
4 3 2 1 0
2 2 2 2 2
16 8 4 2 1
Decimal
( 0 * 16) + (1 * 8) + (0 * 4) + (0 * 2) + (0 * 1) = 8

Binary 1 ​ ​ ​0 ​ ​ ​ 0 ​ ​ ​0 ​ ​ 0

4 3 2 1 0
2 2 2 2 2
16 8 4 2 1
Decimal (1 * 16) + (0 * 8) + (0 * 4) + (0 * 2) + (0 * 1) = 16

Example: Convert (1011010)2 to Decimal: Exercise: Convert (1100111) to Decimal: 2

Binary 1 0 ​ ​ 1 ​ ​ ​1 ​ ​ ​ 0 ​ ​ ​1 ​ ​ 0
6 5 4 3 2 1 0
2 2 2 2 2 2 2
64 32 16 8 4 2 1
Decimal (1 * 64) + (0 * 32) + (1 * 16) + (1 * 8) + (0 * 4) + (1 * 2) + (0 * 1) = 64 + 16 + 8 + 2 = 90
0 0
Example: Convert (73) to Binary:
2 = 1 2 -1= 0 10
10
1
2 = 2 1
2 -1= 1
2
2 = 4 2
2 -1= 3 First we need to know how many Binary digits we need to store 73?

23 = 8 3
2 -1= 7 Smaller than
73 digits
24 = 16 24 - 1 = 15 max number = (base) -1
25 = 32 5
2 -1= 31 7
max number = 2 - 1 = 127 Digits = 7
26 = 64 6
2 -1= 63
7 7
2 = 128 2 -1= 127 Big Enough to
store 73
8 8
2 = 256 2 -1= 255 7 Digits

29 = 512 9
2 -1= 511
10 10
2 = 1024 2 -1= 1023 _ _ ​ ​ _ ​ ​ ​_ ​ ​ ​ _ ​ ​ ​_ ​ ​ _
6 5 4 3 2 1 0
2 2 2 2 2 2 2
64 32 16 8 4 2 1

Exercise: Convert (120) to Binary: Does 73 contains 64? YES!

1 _ ​ ​ _ ​ ​ ​_ ​ ​ ​ _ ​ ​ ​_ ​ ​ _
Binary (So far) (1 * 64) = 64

Does 73 contains 64 + 32? (= 96) No!

1 0 ​ ​ _ ​ ​ ​_ ​ ​ ​ _ ​ ​ ​_ ​ ​ _
Binary (So far) (1 * 64) + (0*32) = 64

Does 73 contains 64 + 16? (= 80) No!

1 0 ​ ​ 0 ​ ​ ​_ ​ ​ ​ _ ​ ​ ​_ ​ ​ _
Binary (So far) (1 * 64) + (0*32) + (0 * 16) = 64

Does 73 contains 64 + 8? (= 72) YES!

1 0 ​ ​ 0 ​ ​ ​1 ​ ​ ​ _ ​ ​ ​_ ​ ​ _
Binary (So far) (1 * 64) + (0*32) + (0 * 16) + (1 * 8) = 72

Does 73 contains 72 + 4? (= 76) No!

1 0 ​ ​ 0 ​ ​ ​1 ​ ​ ​ 0 ​ ​ ​_ ​ ​ _
Binary (So far) (1 * 64) + (0*32) + (0 * 16) + (1 * 8) + (0 * 4) = 72

Does 73 contains 72 + 2? (= 74) No!

1 0 ​ ​ 0 ​ ​ ​1 ​ ​ ​ 0 ​ ​ ​0 ​ ​ _
Binary (So far) (1 * 64) + (0*32) + (0 * 16) + (1 * 8) + (0 * 4) + (0 * 2) = 72

Does 73 contains 72 + 1? (= 73) YES!

1 0 ​ ​ 0 ​ ​ ​1 ​ ​ ​ 0 ​ ​ ​0 ​ ​ 1
Binary (So far) (1 * 64) + (0*32) + (0 * 16) + (1 * 8) + (0 * 4) + (0 * 2) + (1 * 1) = 73

Final Answer: (73) = (1001001)


10 2

Before Moving on,


you should be
wondering:

Why we are
interested in Octal
and Hexa?
Binary is important
because computer 0 1
Hardware
understands open
circuit as 0 and
closed circuit as 1

But, binary numbers could get very large and hard for us to read and understand
while programming, for example: (512) = (1000000000) 10 2

Thus, we need a Numbering System to shorten Binary Numbers and, at the same
time, is easy to convert back to Binary

Remember
Positional Numbering Systems

Decimal Binary Octal Hexadecimal


‫النظام العشري‬ ‫النظام الثنائي‬ ‫النظام الثماني‬ ١٦ ‫النظام الستاعشري‬
10,11,12,13,14,15
Set of symbols, S = {0,1,2,3,4,5,6,7,8,9} Set of symbols, S = {0,1} Set of symbols, S = {0,1،2,3,4,5,6,7} Set of symbols, S = {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}

Thousands Hundreds Tens Ones ___ _______ __________ _____ _____ ____________ __________ _____ _____ ____________ __________ _____ _____

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 1 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 1 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 1 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 1

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 2 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 0 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 2 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 2

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 3 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 1 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 3 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 3

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 4 ​ ​ ​0 ​ ​ ​ ​ 1 ​ ​ ​0 ​ ​ 0 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 4 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 4

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 5 ​ ​ ​0 ​ ​ ​ ​ 1 ​ ​ ​0 ​ ​ 1 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 5 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 5

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 6 ​ ​ ​0 ​ ​ ​ ​ 1 ​ ​ ​1 ​ ​ 0 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 6 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 6

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 7 ​ ​ ​0 ​ ​ ​ ​ 1 ​ ​ ​1 ​ ​ 1 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 7 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 7 1 Full Octal Digit = 3 Full Binary Digits


​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 8 ​ ​ ​1 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 0 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 0 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 8

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 9 ​ ​ ​1 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 1 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 1 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 9 1 Full Decimal Digit DOES NOT Equal Full Binary Digits!


​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 0 ​ ​ ​1 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 0 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 2
​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ A

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 1 ​ ​ ​1 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 1 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 3 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ B

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 2 ​ ​ ​1 ​ ​ ​ ​ 1 ​ ​ ​0 ​ ​ 0 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 4 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ C

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 3 ​ ​ ​1 ​ ​ ​ ​ 1 ​ ​ ​0 ​ ​ 1 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 5 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ D

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 4 ​ ​ ​1 ​ ​ ​ ​ 1 ​ ​ ​1 ​ ​ 0 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 6 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ E

​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 5 ​ ​ ​1 ​ ​ ​ ​ 1 ​ ​ ​1 ​ ​ 1 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 7 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ F 1 Full Hexadecimal Digit = 4 Full Binary Digits


​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 6 1 ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​0 ​ ​ 0 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​2 ​ ​ 0 ​ ​ ​0 ​ ​ ​ ​ 0 ​ ​ ​1 ​ ​ 0

Octal and Hexadecimal are Easier to convert to Binary compared to Decimal


Hence, we prefer to use them to Shorten Binary Numbers.

Octal are used in Older Systems while Hexadecimal is used in Modern Systems.
Converting

Octal, base 8 Binary, base 2

Hexa, base 16

x
using Exponent Method (2 )

Example: Convert (110001) 2 to Octal: Example: Convert (110001) 2 to Hexa:

1 1 ​ ​ 0 ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​0 ​ ​ ​ 0 ​ ​ ​1 Binary 0 ​ ​ ​ ​0 ​ ​ ​ 1
​ 1 ​ ​ ​ ​ ​ ​ ​ ​ ​ 0 ​ ​ ​ ​0 ​ ​ ​ 0 ​ ​ ​1
Binary
3 2 1 0

2
2
2
1
2
0 2 1 0
2 2 2 2 2
3
2
2
2
1
2
0
2 2 2
4 2 1 4 2 1 8 4 2 1 8 4 2 1
Hexa (0 * 8) + (0 * 4) + (1 * 2) + (1 * 1)
Octal (1 * 4) + (1 * 2) + (0 * 1) (0 * 4) + (0 * 2) + (1* 1) (0 * 8) + (0 * 4) + (0 * 2) + (1* 1)

0 + 0 + 2 +1
4+2+0 0+0+1 0+0+0+1
3
6 1 1

Final Answer: (110001) = (61) Final Answer: (110001) = (31)


2 16
2 8

Exercise: Convert (1010101) 2 to Octal: Excersie: Convert (1010101) 2 to Hexa:


Example: Convert (54) 8 to Binary: Exercise: Convert (72)8 to Binary:

Octal
5 4
3 Digits 3 Digits

_ _ ​ ​ _ _ _ ​ ​ _

2 1 0 2 1 0
2 2 2 2 2 2
4 2 1 4 2 1

Does 5 contains 4? YES!

1 _ ​ ​ _
5 Binary (So far) (1 * 4) = 4

3 Digits
Does 5 contains 4 + 2? (= 6) No!
_ _ ​ ​ _
1 0 ​ ​ _
2 1 0 Binary (So far) (1 * 4) + (0*2) = 4
2 2 2
4 2 1
Does 5 contains 4 + 1? (= 5) YES!

1 0 ​ ​ 1
Binary (So far) (1 * 4) + (0*2) + (1 * 1) = 5

Does 4 contains 4? YES!

4 1 _ ​ ​ _
Binary (So far) (1 * 4) = 4
3 Digits

_ _ ​ ​ _ Does 4 contains 4 + 2? (= 6) No!

2 1 0
2 2 2 1 0 ​ ​ _
Binary (So far) (1 * 4) + (0*2) = 4
4 2 1

Does 4 contains 4 + 1? (= 5) No!

1 0 ​ ​ 0
Binary (So far) (1 * 4) + (0*2) + (0 * 1) = 4

Final Answer: (54) = (101 100)


8 2
Example: Convert (AE) to Binary: A --> 10 Exercise: Convert (F9) to Binary:
16 16

Hexa
B --> 11
A E C --> 12
4 Digits 4 Digits
D --> 13
_ _ ​ ​ _ ​ ​ ​ ​ _ _ ​ ​ _ ​ ​ ​ ​ E --> 14
F --> 15
3 2 1 0 3 2 1 0
2 2 2 2 2 2 2 2
8 4 2 1 8 4 2 1

Does A contains 8? YES!

1 _ ​ ​ _ ​ ​ ​ ​
Binary (So far) (1 * 8) = 8

Does A contains 8 + 4? (= 12) No!


A
4 Digits 1 0 ​ ​ _ ​ ​ ​ ​
Binary (So far) (1 * 8) + (0*4) = 8

_ _ ​ ​ _ ​ ​ ​ ​

3 2 1 0 Does A contains 8 + 2? (= 10) YES!


2 2 2 2
8 4 2 1 1 0 ​ ​ 1 ​ ​ ​ ​
Binary (So far) (1 * 8) + (0*4) + (1 * 2) = 10 (--> A)

Does A contains 10 + 1? (= 11) No!

1 0 ​ ​ 1 ​ ​ ​ 0

Binary (So far) (1 * 8) + (0*4) + (1 * 2) + (0 * 1) = 10 (--> A)

Does E contains 8? YES!

1 _ ​ ​ _ ​ ​ ​ ​
Binary (So far) (1 * 8) = 8

Does E contains 8 + 4? (= 12) YES!


E
4 Digits 1 1 ​ ​ _ ​ ​ ​ ​
Binary (So far) (1 * 8) + (1*4) = 12

_ _ ​ ​ _ ​ ​ ​ ​

3 2 1 0 Does A contains 12 + 2? (= 14) YES!


2 2 2 2
8 4 2 1 1 1 ​ ​ 1 ​ ​ ​ ​
Binary (So far) (1 * 8) + (1*4) + (1 * 2) = 14 (--> E)

Does A contains 14 + 1? (= 15) No!

1 1 ​ ​ 1 ​ ​ ​ 0

Binary (So far) (1 * 8) + (1*4) + (1 * 2) + (0 * 1) = 14 (--> E)

Final Answer: (AE) = (1010 1110)


16 2
Converting

(using Binary)
Octal, base 8 Decimal, base 10

(using Binary) (using Binary)


Hexa, base 16

Example: Convert (AE) to Decimal:


16 A --> 10
B --> 11
C --> 12
D --> 13
Step 1: Convert Hex to Binary E --> 14
F --> 15

Hexa
A E
4 Digits 4 Digits

_ _ ​ ​ _ ​ ​ ​ ​ _ _ ​ ​ _ ​ ​ ​ ​

8 4 2 1 8 4 2 1

1 0 ​ ​ 1 ​ ​ ​ ​0 1 1 ​ ​ 1 ​ ​ ​ ​0

Step 2: Convert Binary to Decimal

Binary 1 ​ ​ ​ ​0 ​ 1 ​ ​ 0 ​ ​ 1 ​ ​ 1 ​ ​1 ​ ​ 0

128 64 32 16 8 4 2 1

Decimal (1 * 128) + (0 * 64) + (1 * 32) + (0 * 16) + (1 * 8) + (1 * 4) + (1 * 2) + (0 * 1) = 128 + 32 + 8 + 4 + 2 = 174

Final Answer: (AE) = (174)


16 10

Example: Convert (AE) to Octal: Exercise: Convert (75) to Hexadecimal:


16 A --> 10 8
B --> 11
C --> 12
D --> 13
Step 1: Convert Hex to Binary E --> 14
F --> 15

Hexa
A E
4 Digits 4 Digits

_ _ ​ ​ _ ​ ​ ​ ​ _ _ ​ ​ _ ​ ​ ​ ​

8 4 2 1 8 4 2 1

1 0 ​ ​ 1 ​ ​ ​ ​0 1 1 ​ ​ 1 ​ ​ ​ ​0

Step 2: Convert Binary to Octal

Binary 0 ​ ​ ​ ​1 ​ ​ ​ ​0 ​ ​ ​ ​ ​ ​1 ​ ​ 0 ​ ​ 1 ​ ​ ​ ​ ​ 1 ​ ​1 ​ ​ 0

4 2 1 4 2 1 4 2 1

(1 * 4) + (1 * 2) + (0 * 1)
Octal (0 * 4) + (1 * 2) + (0 * 1) (1 * 4) + (0 * 2) + (1 * 1)

2 5 6

Final Answer: (AE) = (256)


16 8
Before finishing In Decimal
x
In (2 ) In Binary

the Chapter, you 0.5 2


-1

​ ​ ​0 ​ ​ 0 ​ ​ ​. ​ 1
​ ​ ​ ​0 ​ ​ ​0

may winder: 0.25 2


-2
​ ​ ​0 ​ ​ 0 ​ ​ ​. ​ 0
​ ​ ​ ​1 ​ ​ ​0

How about float


-3
0.125 2 ​ ​ ​0 ​ ​ 0 ​ ​ ​. ​ 0
​ ​ ​ ​0 ​ ​ ​1

numbers?!

Example: Convert (101.11) to Decimal


2

Binary 1 ​ ​ ​ ​0 ​ 1 ​ ​ . ​ ​ 1 ​ ​ 1

4 2 1 . 0.5 0.25

Decimal (1 * 4) + (0 * 2) + (1 * 1) ​ ​. ​ ​ (1 * 0.5) + (1 * 0.25)

Final Answer: (101.11) = (5.75)


2 10

Example: Convert (6.25) to Binary Exercise: Convert (19.375) to Binary


10
10

_ _ ​ ​ _ ​ ​ ​ ​ ​ ​ ​. ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​
Too large, we
do not need 8 4 2 1 . 0.5 0.25 0.125
this digit for
number 6! 0 1 ​ ​ 1 ​ ​ ​ ​0 . 0 1 ​ ​ ​ 0

Final Answer: (6.25) = (110.01)


10 2
Chapter 3: Data Storage
‫تخزين البيانات‬

In Chapter 1 we Learned

In Von Neuman Model:

Input/Output Data are stored in Memory.

Programs are stored in Memory and coded by


programmers. In Chapter 2 we Learned
Hence ... both Data and Programs should have the
same format: a sequence of 0s and 1s (like The sequence of 0s and 1s (like 01010101101) is in Binary System.
01010101101)
Binary Numbers can get very large and hard to read, so we use Octal or
Hexadecimal Systems to Shorten Binary Numbers.

We can Convert from Binary to Decimal, Octal, and Hexadecimal using


the 2 Exponent Method.

We can Convert between Decimal, Octal, and Hexadecimal by first


converting the number to Binary and then to the desired system.

But, how to Store different Data Types in Memory using the Binary System?

Data Types
A file containing
many Data
Types is called:
Multimedia file
Numbers Text Audio Images Videos

Among the important issues related to computer Data Types: Among the important issues related to storing Numbers:

Data Compression Storing the sign of the number


We will not
study the
details of
theses issues We will not
in this course! study the
Error Detection and Correction details of Showing the decimal point.
showing the
decimal point
Integers ‫نقصد ب‬
Storing Integer Numbers ‫األرقام الصحيحة من غير‬
‫فاصلة عشرية‬

Unsigned Sign and Magnitude 2's Complement

Always Positive ‫موجب دائما‬ Used to represent positive + and negative - numbers Used to represent positive + and negative - numbers
4-​bit Memory Location
We use the Conversion methods of Chapter 2 The leftmost bit is used to represent the sign The most widely used system in modern computers
0 means positive
If a Memory cell has more digits than what is 1 means negative In this method, the range is divided into negative half and
required for a number, we fill the left digits with 0s Sign
‫اإلشارة‬ positive half with a zero in the middle.
Magnitude
This way, we end up with 2 Symbols for Zero: 0+ and ‫القيمة‬ If the leftmost digit is 0, then this is a positive number
0- .. and they mean the same thing at the end! If the leftmost digit is 1, then this is a negative number
Example: Store 9 in a 7-​bit memory location using unsigned representation:
For example, the following is the Sign and For example, the following is the 2's Complement numbers
7-​bit Memory Location Magnitude numbers using 4-​bits: using 4-​bits:

0 0 0 1 0 0 1

64 32 16 8 4 2 1
Same thing ... 0!
Unsigned

Always Positive ‫موجب دائما‬

We use the Conversion methods of Chapter 2

If a Memory cell has more digits than what is


required for a number, we fill the left digits with 0s

Example: Store 9 in a 7-​bit memory location using unsigned representation:

7-​bit Memory Location

0 0 0 1 0 0 1

64 32 16 8 4 2 1

Exercise: Store 300 in a 16-​bit memory location using unsigned representation:

Example: What is returned from an Output Device (Printer or Monitor) when it


If you are asked retrieves the bit string 10010101 that is stored in memory using unsigned
for output from representation?

memory, then you


need to convert
from Binary to 1 0 0 1 0 1 0 1
Decimal.
128 64 32 16 8 4 2 1

Output = 128 + 16 + 4 + 1 = 149

Exercise: What is returned from an Output Device (Printer or Monitor) when it


retrieves the bit string 1011110 that is stored in memory using unsigned
representation?

But, what would happen if we try to Store a large Number that needs more digits than the
available bits in Memory?

Example: Store 9 in a 3-​bit memory location using unsigned representation:

3-​bit Memory Location

1 0 0 1

!
8 4 2 1
re
o sto
et
ac
sp
No

The stored number now is: 1 instead of 9!

This problem is called: Overflow

A space error: $370 million for an integer overflow

Exercise: Will there be an overflow if we try to store the following decimal numbers in
4-​bit memory location using unsigned representation?

15

16

29
Sign and Magnitude

Used to represent positive + and negative - numbers


4-​bit Memory Location
The leftmost bit is used to represent the sign
0 means positive
1 means negative
Sign
‫اإلشارة‬ Magnitude
This way, we end up with 2 Symbols for Zero: 0+ and ‫القيمة‬
0- .. and they mean the same thing at the end!

For example, the following is the Sign and


Magnitude numbers using 4-​bits:

Same thing ... 0!


Example: Store 9 in a 7-​bit memory location using Sign and Magnitude representation:

7-​bit Memory Location

0 0 0 1 0 0 1

+
-
32 16 8 4 2 1

Example: Store -9 in a 7-​bit memory location using Sign and Magnitude representation:

7-​bit Memory Location

1 0 0 1 0 0 1

+
-
32 16 8 4 2 1

Exercise: Store -300 in a 16-​bit memory location using sign and magnitude representation:

Example: What is returned from an Output Device (Printer or Monitor) when it


retrieves the bit string 10010101 that is stored in memory using sign and magnitude
representation?

1 0 0 1 0 1 0 1
- 64 32 16 8 4 2 1

Output = - (16 + 4 + 1) = -21

Example: Store 9 in a 4-​bit memory location using sign and magnitude representation:

9 in Binary is: 1001, but the leftmost bit is used to indicate the Sign!

4-​bit Memory Location

1 0 0 1

8 4 2 1
The stored number now is: - 1 instead of 9!

This problem is called: Overflow

Exercise: Will there be an overflow if we try to store the following decimal numbers in
6-​bit memory location using Sign and Magnitude representation?

30

45

-8

-32
2's Complement

Used to represent positive + and negative - numbers

The most widely used system in modern computers

In this method, the range is divided into negative half and


positive half with a zero in the middle.
If the leftmost digit is 0, then this is a positive number
If the leftmost digit is 1, then this is a negative number

For example, the following is the 2's Complement numbers


using 4-​bits:

Before
proceeding, we
need to know
how to make 1's
complement

1's Complementing is the operation where we replace each bit with its opposite.

Example: What is the 1' Complement of 10010101?

1 0 0 1 0 1 0 1
0 1 1 0 1 0 1 0

If we apply 1's
complement
two times, we
get the original
number again

Example: Apply the 1's Complement for 10010101 two times:

1 0 0 1 0 1 0 1 Original Number
0 1 1 0 1 0 1 0 First Time
1 0 0 1 0 1 0 1 Second Time

2's Complementing is the operation where we copy all the bits from the right until we copy the
first 1, then we replace each remaining bit with its opposite (like 1's complementing).

Example: What is the 2's Complement of 10010100?

1 0 0 1 0 1 0 0
0 1 1 0 1 1 0 0

Exercise: Store -300 in a 16-​bit memory location using 2' Complement representation:
Example: What is returned from an Output Device (Printer or Monitor) when it
retrieves the bit string 00010100 that is stored in memory using 2's Complement
representation?

0 0 0 1 0 1 0 0

+ 64 32 16 8 4 2 1
0 means a positive number,
so we do not need to apply 2's
complement

Output = + (16 + 4) = 20

Example: What is returned from an Output Device (Printer or Monitor) when it


retrieves the bit string 10010100 that is stored in memory using 2's Complement
representation?

1 0 0 1 0 1 0 0

1 means a negative number,


so we need to apply 2's complement

- 1 1 0 1 1 0 0

- 64 32 16 8 4 2 1

Output = - (64 + 32 + 8 + 4) = -108

Exercise: What is returned from an Output Device (Printer or Monitor) when it


retrieves the bit string 1011110 that is stored in memory using 2's Complement
representation?

Example: Store 9 in a 4-​bit memory location using sign and magnitude representation:

9 in Binary is: 1001, but the leftmost bit is used to indicate the Sign!

4-​bit Memory Location

1 0 0 1

1 means a negative number, - 1 1 1


so we need to apply 2's complement

- 4 2 1
The stored number now is: - 7 instead of 9!

This problem is called: Overflow

Exercise: Will there be an overflow if we try to store the following decimal numbers in
6-​bit memory location using 2's Complement representation?

30

45

-8

-32
Storing Text

Every language contains:


Letters: In English 26 Small Letters (a, b, ... y,z) and 26 Capital Letters (A,B, ... Y, Z)
Numbers: (0,1,2,3,4,5,6,7,8,9)
Punctuations and Special Marks: ( ) * & ^ % $ # @ ! ? < > } { ' " \ | + - = / ...

So, we can store each Letter, Number, or Special Mark with a unique sequence of bit
pattern in a memory location.
Like This

There are many different standards "Codes" in the computing industry to represent the
letters of different languages.

Some of the most common codes:


ASCII
Unicode (UTF-8, UTF-16, UTF-32)

The same letter could have different bit pattern depending on the used Standard
"Code", for example:
A in ASCII is: 01000001
A in Utf-16 is: 0000000001000001

But, how many bits are required to store ALL the Letters, Numbers, and Special Marks in
a given Language?

We can use the Maximum number of symbols formula we studied in Chapter 2:

0 Without Counting the number Zero 0


2 = 1 Number of Digits
1 Maximum number supported by given digits = (Base)
2 = 2
2
2 = 4
23
Smaller than
= 8 90

Example: What is the minimum number of bits are needed to represent a language
24 = 16
that have: 50 letter, 10 numbers, and 30 special marks?
25 = 32
26 = 64
7 Number of Digits
2 = 128 Big Enough to

Maximum number supported by given digits = (Base)


store 90
8
2 = 256
9
2 = 512 Number of Digits
10
2 = 1024 Max = (2) number of symbols = 50 + 10 + 30 = 90

7
Max = (2)

Final Answer: we need 7 bits

Exercise: What is the minimum number of bits are needed to represent a language
that have: 32 letter, 10 numbers, and 22 special marks?
Storing Audio

Audio is a representation of Sound or Music.

Unlike Numbers and Text which are Discrete "Digital" Data, Audio is Continuous
"Analog" Data

Sound
Grade
Intensity

Analog Data - Continuos Data Digital Data - Discrete Data

100 65 80

Ahmad Khalid Saad Student


Time

We can't Count the We can Count the


number of sound waves number of students
"Symbols" because this "Symbols" because this
is Analog Data is Digital Data

Infinite Number of Values

Computer Memory does not have infinite number of locations!

Hence, we need to convert Analog Sound to Digital Data to be stored in Memory.

The conversion process from Analog to Digital include 3 steps:


Sampling: dividing the sound waves into some points to be stored in Memory.
Quantization: giving each sample a quantity value.
Encoding: giving each sample a binary code to be stored on Memory.
Sampling

Few Samples --> bad Accuracy

Sampling

Few Samples --> bad Accuracy

Sampling

More Samples --> better Accuracy

Sampling

More Samples --> better Accuracy

S = Number
of Samples
per Second

Quantization

Usually integers instead of real numbers

This is important to represent sound Intensity


14
15

-4
-10
- 20
Encoding

Usually shift the quantities up to get unsigned integers instead of positive and
negative numbers

34
35

23

16

0 10

Encoding

Bit Patterns

0100010
B= Bit Depth, 0100011

Number of 0010111
bits in the
sample 0010000

0000000 0001010

Bit Rate = B * S

Larger Bit Rate means


better quality

There are different standards "Codes" to store Audio data

There are Lossless Standards


Does not loss any sound details
Uses more samples -> needs more memory
Example: WAV

There are Lossy Standards


Loss some sound details because of data compression
The less samples used -> the less memory is needed -> the less the sound quality is
Example: MP3
Storing Images

Vector Raster
Border Color

Uses Grid of Pixels (Color Points) to store the image in memory, like:
Fill Color Uses Geometric Properties to store the image in memory, like:
The radius, center point, border color, and fill color to describe a circle
Center Point Circle
Scaling up a Raster image may reduce quality if the resolution is low (using fewer pixels
The edge length, center point, border color, and fill color to describe a rectangle
Radius to describe the same image)

It is easy to scale up or down a vector image without losing quality or requiring extra
Increasing the Resolution (using more pixels) would require extra memory
memory
Border Color
It is good for complex images, web images, and for printing
It is good for basic images, diagrams, and logos
e
gl
an
ct

Fill Color
It is d for not good for basic images, diagrams, logos, and professional drawing because
Re

It is not good for complex images with a lot of shapes and colors
Center Point
it is hard to retain the quality if scaling is needed.
Edge

It must be converted to Raster for printing


The Raster Graphics standards or "Encodings" include

The Vector Graphics standards or "Encodings" include


Storing a real Image (Analog) in Memory (Digital) requires conversion steps similar to
the Audio Conversion:
Scanning (like Sampling in Audio): diving the image into pixels
Encoding (like Quantization and Encoding in Audio): giving a color to each pixel
and using a number of bits in a bit pattern (like Bit Depth in Audio) to store this
color in Memory
Raster

Uses Grid of Pixels (Color Points) to store the image in memory, like:

Scaling up a Raster image may reduce quality if the resolution is low (using fewer pixels
to describe the same image)

Increasing the Resolution (using more pixels) would require extra memory

It is good for complex images, web images, and for printing

It is d for not good for basic images, diagrams, logos, and professional drawing because
it is hard to retain the quality if scaling is needed.

The Raster Graphics standards or "Encodings" include

Storing a real Image (Analog) in Memory (Digital) requires conversion steps similar to
the Audio Conversion:
Scanning (like Sampling in Audio): diving the image into pixels
Encoding (like Quantization and Encoding in Audio): giving a color to each pixel
and using a number of bits in a bit pattern (like Bit Depth in Audio) to store this
color in Memory

Main Types of Colors Bit Patterns

True Colors Indexed Colors

Uses 24 Bits: Uses only 8 Bits to represent a Subset of the True Colors that
8 Bits to represent Red, R are present in a given image.
8 Bits to represent Green, G 8
8 Bits to represent Blue, B So, we could represent 2 different colors --> 256 colors

24
So, we could represent 2 different colors --> ~16 Million colors! It requires less Memory compared to True Colors, but the
quality would be poorer
It requires more Memory compared to Indexed Colors, but it has
better quality Suitable for online images

Suitable for Images to printed or complex images and photos Some Encodings include GIF

Some Encodings include: PNG, and JPEG


Storing Videos

Video is a group of images that appear rapidly after each other

Each image is called a Frame (Like to Pixel in Raster or Sample in Audio)

So, if we know how to store an image, we would know how to store a Video which is a
set of different images that appear in some order and speed.

We will not study the details of this process in this course.


Chapter 4: Operations on Data
‫العمليات على البيانات‬
In Chapter 1 we Learned

In Von Neuman Model:

Input/Output Data are stored in Memory.

Programs are stored in Memory and coded by


programmers. In Chapter 2 we Learned
Hence ... both Data and Programs should have the
same format: a sequence of 0s and 1s (like The sequence of 0s and 1s (like 01010101101) is in Binary System.
01010101101)
Binary Numbers can get very large and hard to read, so we use Octal or
Hexadecimal Systems to Shorten Binary Numbers.

We can Convert from Binary to Decimal, Octal, and Hexadecimal using


the 2 Exponent Method.

We can Convert between Decimal, Octal, and Hexadecimal by first


converting the number to Binary and then to the desired system.

In Chapter 3 we Learned

We can store Different Data Types in Memory using a Bit Pattern,


which is a sequence of 0s and 1s (like 01010101101) is in Binary System.

We can store Numbers Using: Unsigned, Sign and Magnitude, or 2's


Complement Representation.

We can store Text using some of the well known Encodings like ASCII
and Unicode. The number of bits needed to represent a language
depends on the total number of symbols available in that language.

We can store Analog Audio by Converting it to Digital Data in Memory


using 3 main steps: Sampling, Quantisation, and Encoding.

We can store Analog Images by Converting it Digital Data stored using


Raster Method where we use a grid of pixels to represent the original
image.

Also, we can store Simple Images and logos using the Vector method
where we represent the image using its geometric properties like
radius and central point.

There are two main encodings to represent colors in stored Images: True
Colors - 24 bits and Indexed Colors - 8bits.

Since a Video is a set of continuous Images shown immediately after


each other, we select "Sample" many images from a video clip and call
them Frames and then we store them in Memory as Raster Images.
In this Chapter, we will learn how to make some Operations on the stored Data Types in Memory

Data
Operations

Logic Shift Arithmetic


Operations Operations Operations
‫العمليات المنطقية‬ ‫عمليات اإلزاحة‬ ‫العمليات الحسابية‬

Multiplication is a series of repeated additions


Each of the Logical Operations we will study could be applied on two levels: Division is a series of repeated subtractions
Logical Shift Arithmetic Shift Operations
Bit Level: applying the operation on 1 bit only There are more efficient methods to compute Multiplication and Division, Booth Sign and
Operations (For 2's Complement Numbers) 2's Complement
Pattern Level: applying the operation on a sequence of n bits Procedures, but they are beyond the scope of this course. Magnitude
Logic
Operations
‫العمليات المنطقية‬

Each of the Logical Operations we will study could be applied on two levels:
Bit Level: applying the operation on 1 bit only
Pattern Level: applying the operation on a sequence of n bits

1 0 1 ..... 0 1 1

0 1 2
n-2 n-1 n

In Boolean Algebra, a bit could have two values:


0 --> False
1 --> True

The Four main Logical Operations we will study are:

Not AND OR XOR

‫عكس‬
‫ االثنين معا‬- ‫مع‬ ‫ أحد العناصر أو كالهما معا‬-‫أو‬ ‫ أحد العناصر فقط وليس كالهما‬- ‫أو الحصرية‬
Unary Operator
Binary Operator Binary Operator Binary Operator
The output is the 1'st
If x = 0 or 1 Then x AND 0 -> 0, 0 AND x -> 0 If x = 0 or 1 Then x OR 1 -> 1, 1 OR x -> 1 If x = 0 or 1 Then 1 XOR x -> Not x , x XOR 1 -> Not x
Complement of the input

V OR W

Exercise: Prove using a Truth Table that x XOR y <-> [x AND (NOT y)] OR [(NOT x) AND y]
Exercise: Fill the blanks with the correct
Operator [Not, AND, OR, XOR] V W

1. The sentence "Please khalid, buy for me chicken or beef sandwich" can be
represented using: X AND (NOT y) (NOT x) AND y
X Y NOT Y NOT X V OR W x XOR y
V W

Buy Chicken Sandwich .............. Buy Beef Sandwich


0 0

2. The sentence "Please khalid, buy for me chicken or beef sandwich, if you 0 1

can buy both it will be great because I am hungry!" can be represented using:
1 0

Buy Chicken Sandwich .............. Buy Beef Sandwich


1 1

3. The sentence "Please khalid, buy for me both chicken and beef sandwiches,
I am hungry!" can be represented using:

Buy Chicken Sandwich .............. Buy Beef Sandwich

4. The sentence "Please khalid, only buy for me a beef sandwich, I do not like
chicken!" can be represented using:

( ........... Buy Chicken Sandwich) .............. Buy Beef Sandwich


Logical Operations on the Pattern Level are the same as on the Bit Level but Exercise: calculate the result of passing the input bit patterns into the
each operation is applied to every bit in the pattern. given logical circuit:

?
A1= 1 0 1 1 0 0 0 0 AND

A1 =

?
Output = 0 1 1 1 1 1 0 1
A1 = NOT
Exercise: Apply the following Operations on the given bit patterns: A2 = 0 1 0 0?1 1 1 1

A2 = Output =
10011000 10011000 10011000
10011000 NOT AND OR XOR A2 =
00101010 00101010 00101010
?
A3 = 1 1 0 0 1 1 1 1 OR

A3 =

?
01100111
?
00001000
?
10111010
?
10110010

A3 =

XOR

Output =

Logical Operations Applications

A Mask is a way to
Complementing Unsetting select specific bits to Setting Flipping
be changed, like a
‫قلب كل الخانات‬ ‫تصفير خانات‬ Ruler mask ‫مأل خانات‬ ‫قلب خانات‬
Not AND OR XOR
Remember: x OR 0 -> 1 (Set) Remember: x XOR 1 -> NOT x (Flip)
Exercise: Complement 11011010 Remember: x AND 0 -> 0 (Unset) Hence, the Setting Mask is 1 Hence, the Flipping Mask is 1
Hence, the Unsetting Mask is 0
11011010 NOT

Exercise: Unset the first 3 bits and Exercise: Set the first 3 bits and last 2 Exercise: Flip the first 3 bits and last
last 2 bits (from left to right) bits (from left to right) 2 bits (from left to right)

?
00100101
input 10011000 input 10011000 input 10011000
AND OR XOR
mask ________________ mask ________________ mask ________________

Result Result Result

input 10011000 input 10011000


input 10011000 OR

?
XOR

?
AND mask 11100011 mask 11100011

?
mask 00011100
11111011
Result Result 01111011
Result 00011000
Shift
Operations
‫عمليات اإلزاحة‬

Logical Shift Arithmetic Shift Operations


Operations (For 2's Complement Numbers)

Logical Shift Logical


Circular Shift
(Rotate)

Left Right
(Multiply ×) (Divide ÷)
Left Right Left Right

Exercise: Apply logical left shift Exercise: Apply logical right shift
Exercise: Apply Circular logical left shift In Decimal: In Binary: In Decimal: In Binary:
Exercise: Apply Circular logical right shift

input 10011000 17 0001 1700 0100


input 10011000 input 10011000
input 10011000 8421 8421
Left Shift Right Shift
<---- ×10 -- Left Shift ---- ÷10 --> Right Shift
<---- ×2 -- ---- ÷2 -->
170 170
input 10011000 0010 0010
input 10011000

?
00110000 ?
01001100
input
?
10011000

00110001
input
?
10011000

01001100
Left Shift
<----×10 --
8421

Left Shift
Right Shift
---- ÷10 -->
8421

Right Shift
1700 <----×2 -- 17 ----÷2 -->

0100 0001
8421 8421

Exercise: Apply Arithmetic Left shift Exercise: Apply Arithmetic Right shift

input 11001110 input 11001110

input 11001110 input 11001110

? ?
10011100 11100111

Note: Note:

11001110 in Decimal = -50 11001110 in Decimal = -50

10011100 in Decimal = -100 11100111 in Decimal = -25

Exercise: Apply Arithmetic Left shift


Exercise: is it possible to get an overflow after
applying Arithmetic Right Shift?
input 01111111

input 01111111

00000010

?
Note:

01111111 in Decimal = 127

00000010 in Decimal = -2

BUT 127 * 2 = 254

We got an overflow!
Arithmetic
Operations
‫العمليات الحسابية‬

Multiplication is a series of repeated additions


Division is a series of repeated subtractions
There are more efficient methods to compute Multiplication and Division, Booth
2's Complement
Procedures, but they are beyond the scope of this course.

When adding or subtracting two numbers, we start


from the right bits.
A 10011010
+
B 01011011

Then, we will write the sum result and the carry for
the next bit on the left:

Carry Carry Carry


​ ​ ​ ​ ​1 ​ ​ ​ ​ ​0 ​ ​ ​ ​1 1

A 10011011 A 10011010 A 10011011


+ + +
B 01011011 B 01011011 B 01011011

Sum ​ ​ ​ ​ ​ 0 Sum ​ ​ ​ ​ ​ 1 Sum ​ ​ ​ ​10

You already knows that A - B <-> A + (-​B)


You also learned in Chapter 3 that -​B is the 2's complement
of B --> 1st complement of B + 1 --> (B + 1)
B 01011011

Hence: A - B <-> A + (B + 1) 1's


B 10100100
Complement

2's
(B + 1) 10100101
Complement

To Add or Subtract numbers stored in 2's


Complement, we just follow the following flow
chart:

Exercise: For the following 2's Complement numbers, Add A to B


A 10011010 B 01011011
Exercise: For the following 2's Complement numbers, Add A to B
A 10011010 B 01011011

Carry 0011010

?
A 10011010 -102 (A + 1) 0 1 1 0 0 1 1 0 -102

+
B 01011011 91

Sum 11110101 -11 (Sum + 1) 0 0 0 0 1 0 1 1 -11

Exercise: For the following 2's Complement numbers, Subtract B from A


A 10011010 B 00011010

A 10011010 -102 (A + 1) 0 1 1 0 0 1 1 0 -102

B 00011010 26

+
Carry

(B + 1)
A
1111110

10011010

11100110
? -102

-26

Sum 10000000 -128 (Sum + 1) 1 0 0 0 0 0 0 0 -128

Exercise: For the following 2's Complement numbers, Subtract A from B

A 10011010 B 01011011

B 01011011 91
-

A 10011010 -102 (A + 1) 0 1 1 0 0 1 1 0 -102

?
Carry 1111110

91
B 01011011
+

(A + 1) 01100110 102

Sum 11000001 -63 (Sum + 1) 0 0 1 1 1 1 1 1 -63

91 + 102 = 193, why we got -63 ?!

We got an Overflow!

The Range of supported 2's complement numbers using 8 bits is:

?
7 7
-2 , 0 , 2 - 1

-128, 0 , +127
Arithmetic
Operations
‫العمليات الحسابية‬

Multiplication is a series of repeated additions


Division is a series of repeated subtractions
There are more efficient methods to compute Multiplication and Division, Booth Sign and
Procedures, but they are beyond the scope of this course. Magnitude

Number A stored in a 4-​bit Memory Location

Remember: a number, lets call it A, stored in Sign


and Magnitude looks like:
Sign
‫اإلشارة‬ Magnitude
Overflow
AS ‫القيمة‬
‫الفائض‬
AM
O

To Add or Subtract numbers stored in Sign and


Magnitude, we just follow the following flow chart:

No need to
memorize this
chart, I will
give it to you
in the exam :)

Why these rules?!


Why these rules?!

We can convert subtraction to addition to the


complement of the other number: A S
AM

A 11011 - 11
- B BM
S
B 00011 +3

​ ​ ​ ​1 1
Carry
A S
AM

A 11011 - 11
+ B BM
S
B 10011 -3

R S RM
Sum ​ ​ ​ ​1 1 1 1 0 - 14
R
No overflow!

We need to distinguish between addition and


subtraction:
If both A and B have the same sign (0 and 0 or
1 and 1) we should do a simple addition.
If B has a different sign than A (1 and 0 or 0 A S
B S
A S
B S

and 1) then we should follow a different


Same Sign
formula.
That is what we get if we use an XOR! Different Sign

​ ​ ​ ​1 1
Carry Carry​ ​ ​ 1 1​ 1
Adding two numbers, A and B, with the same sign is A S
AM
A S AM

simple: just add the Magnitudes and keep the sign A 11011 - 11 A 11011 - 11
+ B BM + BS B M
the same. B
S
10011 -3 B 11011 - 11
If you need an extra bit, then there is an
R S RM
overflow and your result is wrong. Sum ​ ​ ​ ​1 1 1 1 0 - 14 Sum
RS O R M
​ ​ ​ ​1 1 0 1 1 0 -5
R R
No overflow! Overflow!

​ ​ ​ ​1 1
Carry
A S
AM

A 11011 - 11

Adding two numbers, A and B, with different signs is + B S


BM
B 00011 +3
not easy, check this example:
R S RM
Sum ​ ​ ​ ​1 1 1 1 0 - 14
R ​ ​ ​ 0 ​ 1110 + 14

None of the above is the correct answer, -8 !

For that, we add the Magnitude of AM, to the 2's


complement of the Magnitude of BM.
If we get an overflow, we understand that the A 1110 14 Big
M
2's complement of BM is large --> so the
original BM is small --> A M is larger --> we use 2's
Comp.
(A
M
+ 1) 0010 2 Small

the sign of A M
If we do not get an overflow, we understand
A 0001 1 Small
that the 2's complement of BM is small, --> so M

the original BM is big --> A M is smaller --> we 2's


(A + 1) 1111 15 Big
Comp. M
apply the 2's complement to the Result RM
and use the sign of BS .

A S
AM A AM
S

A 11011 - 11 A 00011 +3
+ B BM + B BM
S S
B 00011 +3 B
11011 - 11

​ ​ ​ 1
​ 111 ​ ​ ​ ​ 111
Carry Carry
A S AM A S AM

A 11011 A 00011

+ B (BM+ 1) + B (BM+ 1)
S S
B 01101 Big B 10101 Small

O RM RM
Sum ​ ​ ​ ​1 1 0 0 0 Sum ​ ​ ​ ​ 1 0 0 0
R R
M Overflow! M No Overflow!

Sum R S RM Sum R S RM
R ​ ​ ​ ​1 1 0 0 0 -8 R ​ ​ ​ ​1 1 0 0 0 -8
Exercise: For the following Sign and Magnitude numbers, Subtract B from A
A 10010011 B 01011011

A A
S M
A 10010011 -19
- B B
S M
B 01011011 +91 A
S A
M
We expect = -110 A 10010011
+ B B
S M

?
B 11011011

1 XOR 1 --> 0
010011
A 0010011
M

BM 1011011

R 1101110
M

No overflow!

RS RM
R 11101110

We get = -110
Exercise: For the following Sign and Magnitude numbers, Add A to B
A 10010011 B 01011011

A A
S M
A 10010011 -19
+ B B
S M

?
B 01011011 91

We expect: +72

1 XOR 0 --> 1

000111
A 0010011
M

(BM+ 1) 0 1 0 0 1 0 1

R 0111000
M

No overflow!

(RM+ 1) 1001000
R (RM+ 1)
S
R 01001000

We get: +72
Exercise: For the following Sign and Magnitude numbers, Subtract A from B
A 00101110 B 01101110
Chapter 5: Computer Organization
‫تقسيم وترتيب عتاد الحاسوب‬

In Chapter 1 we Learned

In Von Neuman Model:

Input/Output Data are stored in Memory.

Programs are stored in Memory and coded by


programmers. In Chapter 2 we Learned
Hence ... both Data and Programs should have the
same format: a sequence of 0s and 1s (like The sequence of 0s and 1s (like 01010101101) is in Binary System.
01010101101)
Binary Numbers can get very large and hard to read, so we use Octal or
Hexadecimal Systems to Shorten Binary Numbers.

We can Convert from Binary to Decimal, Octal, and Hexadecimal using


the 2 Exponent Method.

We can Convert between Decimal, Octal, and Hexadecimal by first


converting the number to Binary and then to the desired system.

In Chapter 3 we Learned

We can store Different Data Types in Memory using a Bit Pattern,


which is a sequence of 0s and 1s (like 01010101101) is in Binary System.

We can store Numbers Using: Unsigned, Sign and Magnitude, or 2's


Complement Representation.

We can store Text using some of the well known Encodings like ASCII We can apply different Operations on the Stored Data Types in Memory :
and Unicode. The number of bits needed to represent a language Logical Operations:
depends on the total number of symbols available in that language. Not
AND
We can store Analog Audio by Converting it to Digital Data in Memory OR
using 3 main steps: Sampling, Quantisation, and Encoding. XOR
Shift Operations:
We can store Analog Images by Converting it Digital Data stored using Logical
Raster Method where we use a grid of pixels to represent the original Circular
image. Arithmetic
Left (Multiply)
Also, we can store Simple Images and logos using the Vector method Right (Divide)
where we represent the image using its geometric properties like Arithmetic Operations:
radius and central point. Addition and Subtraction of 2's Complement Numbers
Addition and Subtraction of Sign and Magnitude Numbers
There are two main encodings to represent colors in stored Images: True
Colors - 24 bits and Indexed Colors - 8bits.

Since a Video is a set of continuous Images shown immediately after


each other, we select "Sample" many images from a video clip and call
them Frames and then we store them in Memory as Raster Images.
In this Chapter, we will learn how to the Computer Components, are Organized. Particularly, we will learn about
the Memory that stores the Data Types, the CPU that perform the Data Operations, and the External Devices
that transfer, store, and present these Data Types.

Program

Input/Output Data

Input/Output Data

Program Memory

Memory

Von Neuman Architecture Turing Architecture

Memory
RAM - Random Access Memory

Von Neuman Hardware


Another View
A Little Story!

You are an artist

Working in a project to produce a Paper House Model

You need to use a set of tools

You need to take your tools to your company's workstation

You put your tools in a bag and go to your company

Your table is small, so you take out SOME of your tools and put them on the table to work
Then, you PUT BACK your used tools in your bag, and get the other tools needed

Taking tools from the Bag and putting them again muliple times WASTES TIME and Slow
your Progress

Having a LARGE TABLE will enable you to put all your tools at one time which would saves
you some time and make your work FASTER

For Computers

Data Operation Processor

The Artist is the CPU


Temporary Space - Does not save data when electricity off
Expensive, Compared to Hard disk

The Table is the Memory


CD
DVD
Floppy Disk
The Bag is the Hard Disk Flash Memory

Cheap Permanent Space - Saves data when electricity off


Central Processing Unit - CPU
‫وحدة المعالجة المركزية‬
Performs Data Operations

Arithmetic Logic Unit - ALU Control Unit Registers


‫وحدة الحسابات الرياضية والمنطقية‬ ‫وحدة التحكم‬ ‫سجالت المعالجة‬
Controls the flow of signals from one component to the other Ultra Fast, small, and temporary storage locations

Data Instruction Program


Registers Register - IR Counter - PC
‫سجالت البيانات‬ ‫سجل األمر البرمجي‬ ‫سجل األمر البرمجي‬
‫الحالي‬
How CPU and Memory work together?
Machine Cycle:
1. Fetch ‫استورد‬: Load the current Instruction the PC
points at First Cycle Second Cycle
2. Decode ‫اقرأ‬: Read and understand the loaded
Sample Code in Memory Sample Code in Memory
instruction.
3. Execute ‫نفذ‬: Do the task written in the decoded 10101010 10101010

ROM ROM
instruction. 10101010 10101010
OS Info OS Info
14 10101010 Cannot be Erased 14 10101010 Cannot be Erased
20

3. Execute
10101010 10101010

3. Execute
0 Load 4 to R0
0 Load 4 to R0

Load 5 to R1 Load 5 to R1
0 1 1 1
RAM RAM
Add R0 to R1, Save in R2 Add R0 to R1, Save in R2
2. Decode Load 4 to R0 1. Fetch 2 Program and Data 2. Decode Load 5 to R1 1. Fetch 2 Program and Data
3
Move R2 to 6 Can be Erased 3
Move R2 to 6 Can be Erased

4 14
4 14

5 20
5 20

6 6

Third Cycle Fourth Cycle

Sample Code in Memory Sample Code in Memory

10101010 10101010

ROM ROM
10101010 10101010
OS Info OS Info
3. Execute 14 10101010 Cannot be Erased 14 10101010 Cannot be Erased
20 20
34 10101010 34 10101010

0 Load 4 to R0
0 Load 4 to R0

Load 5 to R1 Load 5 to R1
2 1 3 1
RAM RAM
1. Fetch Add R0 to R1, Save in R2 Add R0 to R1, Save in R2
2. Decode Add R0 to R1 Save in R2
2 Program and Data 2. Decode Move R2 to 6
2 Program and Data
3
Move R2 to 6 Can be Erased 1. Fetch
3
Move R2 to 6 Can be Erased

3. Execute
4 14
4 14

5 20
5 20

6 6 34

34
Memory Types

Main memory Cache Memory


‫الذاكرة الرئيسية‬ ‫الذاكرة المؤقتة‬

The memory where the loaded programs and data are located Faster, but much smaller, than Main Memory that stores parts
of the program or data that could be useful for the next machine
cycles
When fetching a new instruction from the Main Memory, the
next few instructions would be fetched and stored in the
cache.
In the next cycle, the Control Unit would try to fetch the next
Random Access Read-​Only Memory - Instruction from the Cache.
Memory - RAM ROM If the instruction is found then we would save a lot of
‫ذاكرة الوصول العشوائية‬ ‫ذاكرة القراءة فقط‬ time.
If the instruction is not found, then the Control Unit
would fetch it (with the following instructions) from
the Main Memory.

Static Ram - SRAM Dynamic RAM -


‫الذاكرة الثابتة‬ DRAM Programmable Erasable Electrically Erasable
Faster ‫الذاكرة المتغيرة‬ Read-​Only Memory Programmable Programmable Read-​
Slower - PROM Read-​Only Memory Only Memory -
Can't be erased - EPROM EEPROM
Can be using Can Be erased
special hardware

The Main Memory contains Storage Locations


Each Location has a unique identifier, called Address

Data is transferred to and from Memory in groups of bits called Words


A Word could be 8 bits, 16 bits, 32 bits, or 64 bits (and maybe more in the future!)
An 8-​bits Word is called Byte
16-​bits Word -> 2 Bytes Word
32-​bits Word -> 4 Bytes Word
How CPU and Memory work together using Cache?
Second Cycle

First Cycle Sample Code in Memory

10101010
Sample Code in Memory
ROM
10101010
10101010
OS Info
ROM 14
10101010 Cannot be Erased

3. Execute
10101010 20
OS Info
14 10101010
10101010 Cannot be Erased

3. Execute
10101010 0 Load 4 to R0

Load 5 to R1
0 Load 4 to R0 1 1
RAM
2. Decode Load 5 to R1 Add R0 to R1, Save in R2
0 1
Load 5 to R1 2 Program and Data
RAM
2. Decode Load 4 to R0 Add R0 to R1, Save in R2 3
Move R2 to 6 Can be Erased
2 Program and Data

1. Fetch
1. Fetch
Move R2 to 6 Can be Erased 4 14
3 Cache
4 14 5 20

Cache 0 Load 4 to R0

5 20 6
1. Fetch

0 Load 4 to R0 1 Load 5 to R1

6
1 Load 5 to R1

Fourth Cycle
Third Cycle
Sample Code in Memory
Sample Code in Memory
10101010
10101010
ROM
ROM 10101010
10101010 OS Info
OS Info 14
3. Execute 14 10101010 Cannot be Erased
20
10101010 Cannot be Erased 20
34
10101010
34
10101010

0 Load 4 to R0
0 Load 4 to R0

3. Execute
Load 5 to R1
3 1
2 1
Load 5 to R1
RAM
RAM 2. Decode Add R0 to R1, Save in R2 Add R0 to R1, Save in R2
2. Decode Add R0 to R1, Save in R2 Add R0 to R1, Save in R2 2 Program and Data
2 Program and Data
3
Move R2 to 6 Can be Erased
3
Move R2 to 6 Can be Erased
1. Fetch

1. Fetch
1. Fetch
4 14
4 14
Cache
Cache 5 20
5 20
2 Add R0 to R1, Save in R2
2 Add R0 to R1, Save in R2
6 34
6 3 Move R2 to 6
3 Move R2 to 6

34
Another Little Story!

In a far away country, the government decided to divide a desert land to new families
so they could build their dream homes!

The total Land


2
Area is 4000 M

4000 M^2

To encourage more people to live in that far away desert, the government decided to
give each family a 1000 M^2 land.

House
Number

1 1000 M^2

2 1000 M^2

3 1000 M^2

4 1000 M^2

But so many families wanted to live there, so the government changed its mind and
decided to give each family only 500 M^2.

House House
Number Number

1 500 M^2 500 M^2 5

2 500 M^2 500 M^2 6

3 500 M^2 500 M^2 7

4 500 M^2 500 M^2 8

For Computers

4000 M^2
The Total Area is -> Memory Size

Each Land is -> Memory Location (Word) 500 M^2

Each House Number is -> Word Address 1

The Total Number of Possible Addresses Using 1 decimal digit we can get: 10 Addresses

using the given digits -> Address Space 0 2 4 6 8 Without Counting the number Zero 0
Number of Digits
1 3 5 7 9 Maximum number supported by given digits = (Base)
Telling same story for a Computer:

Memory size = 8 Bytes Word = 2-​Bytes Word = 1-​Byte

Address
Address Address

00 2-​Bytes

8 Bytes 01 2-​Bytes
000 1-​Byte 1-​Byte 100

001 1-​Byte 1-​Byte 101


10 2-​Bytes
010 1-​Byte 1-​Byte 110
11 2-​Bytes
011 1-​Byte 1-​Byte 111

Exercise: A Computer has 32 MB (Megabytes) of Memory. How many Exercise: A Computer has 32 MB (Megabytes) of Memory. How many
bits are needed to address any single byte in Memory? bits are needed to address any 2-​bytes in Memory?

Exercise: A Computer has 256 GB (Gigabytes) of Memory. Each Word


is 8-​Bytes of memory. How many bits are needed to address any single
Word in Memory?
Input / Output Subsystems
‫أنظمة اإلدخال واإلخراج‬

Non-​Storage Devices Storage Devices


‫أجهزة غير تخزينية‬ ‫أجهزة تخزينية‬

Allow the computer to communicate with the outside world, but Can store large amounts of Data
without storing Data. Examples include: Nonvolatile: not erased when electricity is off
Cheaper than Main Memory
Keyboard

Monitor
Magnetic Optical
Printer
‫ممغنطة‬ ‫ضوئية‬

Magnetic Disk Magnetic Tape CD-​ROM CD-​R CD-​RW DVD


‫القرص الممغنط‬ ‫الشريط الممغنط‬
Magnetic
‫ممغنطة‬

Magnetic Disk Magnetic Tape


‫القرص الممغنط‬ ‫الشريط الممغنط‬

SSD

HDD Contains: Contains:


A set of vertical Disks, each Disk has: Tape Surface that contains:
Tracks 9 Tracks: 1 Byte of Data + 1 bit for Error Detection
Intertrack Gap: Space between Tracks A set of Data Blocks, but without addressing
Sector: Divides the Tracks to sections that could mechanism like the Magnetic Disk Sectors
be read directly Two Reels to mount the Tape
Intersector Gap: Space between Sectors Read/Write heads
Controller that contain Read/Write heads for each Supports Sequential Data Access
Disk Cheaper, but slower, than Magnetic Disk
Supports Random Data Access Good for long-​term backups
Speed factors: Good for Legacy Systems
Rotational Speed
Seek Time
Transfer Time
Optical
‫ضوئية‬

CD-​ROM CD-​R CD-​RW DVD

Read-​Only Similar to CD-​R but you can erase the data and write on the
Similar to CD-​ROM but you write the Data using your
Massively produced in factories using Molds CD again
Personal Computer, PC
Cost-​Efficient if you want mass production More expensive than CD-​R
Cost-​Efficient if you want only few copies
Supports Random Data Access

Byte + 6 Bits for


Error Detection
Connecting CPU and Memory ≥ Memory Word 0000 --> Memory Word
​Normally connected using 3 groups of connections: 0001
Address Space
0010
1. Data Bus: the size should be ≥ Memory Word 0011
2. Address Bus: the size should be ≥ Address Space ≥ Address Bits 4 Bits Address
3. Control Bus: the size should be ≥ Number of Supported Commands
≥ Control Bits supported
Commands
= 14
Connecting I/O Devices
I/O Devices cannot be connected directly to the busses
Because they are electromechanical, magnetic, or optical devices --> much slower
than the CPU and Memory
Hence, we need I/O Controllers to connect the I/O devices to the busses

USB - Universal Serial Bus


SCSI - Small Computer System Interface FireWire - IEEE Standard 1394
SCSI - Small Computer System Interface

Developed by Macintosh Computers in 1984


Parallel Interface with 8, 16, or 32 connections (each connection is a bit).
Speeds between 400 Mb/sec (50 MB/Sec) and 2560 Mb/sec (320 MB/Sec) in
latest versions.
Provide Daisy-​Chained connection (Serial).
Both end of the chain must be connected to a device called Terminator.
Each device must have a unique address (targetID).
FireWire - IEEE Standard 1394

Designed in 1986.
Serial Interface (packet of bits transfer).
High speeds between 400 Mb/sec and 3200 Mb/sec in latest versions.
It can connect up to 63 devices in daisy chain or tree topology.
There is no need for the Terminator.
USB - Universal Serial Bus

Designed in 1996.
Serial Interface (packet of bits transfer).
USB 2.0 has Speeds of 1.5 Mb/sec, 12 Mb/Sec and 480 Mb/sec:
The lower data rate for slow devices like keyboard and mouse
The medium data rate is for printers
The high data rate for hard disks.
USB 2.0 can connect up to 127 devices in tree topology.
The USB Controller is called the Root Hub.
The Root Hub is aware of all the devices under it in the tree, but other hubs have no idea
about the devices above it, except for the Root Hub.
Devices could be added or removed from the tree without powering down the network.
USB 2.0 uses 4 pins:
2 wires for power (5 V and Ground) to power low power devices (high power devices
require external power source).
2 twisted wires (to reduce data noise) to transfer data, address, and control
signals.
Data transfered in Packets starting with address part (device identifier), Control part, and
Data part.
All Devices in the path will receive the packet but only the device with the device
identifier will accept it.
USB 2.0 uses 2 different connectors:
Type A (and mini A): a rectangular downstream connecter to connect the device to the
Hub
Type B (and mini B): a square upstream connecter to connect the hub to the device
Addressing Input/Output Devices
The CPU usually use the same Buses to transfer Data to/from Main Memory and I/O
Devices.
Transferring to/from Main memory is straight forward
If the data transfer is to/from an I/O Device, then we have two methods to do it:

Isolated I/O Addressing Memory-​Mapped I/O Addressing

The I/O Devices would have their Own Address Space The I/O Devices would have their Shared Address Space with the Main
Hence, the CPU need to use Different Control Commands for the I/O Memory
Devices. Hence, the CPU could use the Same Control Commands for both the
A duplicate set of Control Commands for each I/O Device Main Memory and the I/O Devices.
We need to count the Data Registers of the I/O Devices in the
Exercise: If you are using Isolated-​Mapping and your CPU supports 4 Commands, your Address Space of the Main memory.
Main Memory size is 16 KB, your Word size is 4 Byte, your CPU has 16 Data Registers
Exercise: If you are using Memory-​Mapped Addressing and your CPU supports 4
and your computer can support up to 3 I/O Devices each with 4 Data Registers, what
Commands, your Main Memory size is 16 KB, your Word size is 4 Byte, your CPU has 16
are the sizes of your Data Bus, Address Bus, and Control Bus?
Data Registers, and your computer can support up to 3 I/O Devices each with 4 Data
Registers, what are the sizes of your Data Bus, Address Bus, and Control Bus?

64005 64006

64007 64008

Supported Commands (Control Commands)

Supported Commands (Control Commands)

Read 00

Answer: Read 00

#Symbols = 4 Answer:
Data Bus Size = Write 01
#Symbols = 4
Data Bus Size = Write 01

Address Bus Size =


Move 10 Address Bus Size =
Control Bus Size = Move 10

Control Bus Size =


Halt 11

Halt 11

0
2 = 1
1
2 = 2 0
2 2 = 1
2 = 4 1
2 = 2
23 = 8 2
2 = 4
24 = 16
23 = 8
25 = 32
24 = 16
26 = 64
7 25 = 32
2 = 128
8 26 = 64
2 = 256 7
9 2 = 128
2 = 512 8
10 2 = 256
2 = 1024 9
11 2 = 512
2 = 2048 10
12 2 = 1024
2 = 4096 11
13
2 = 2048
2 = 8192 12
2 = 4096
13
2 = 8192
A Simple Computer Example
This is an example to show how a computer would work in real life, it includes:
CPU
Main Memory
Input/Output Devices
A Computer should be able to do a set of Instructions (Commands). Each Instruction
consists of two parts:
Operation Code (opcode) ‫الفعل‬-‫األمر‬: Specify the operation
Operand ‫به‬-‫المفعول‬-‫البيانات‬: Specify the address of the data on which the operation
would be performed
Our example simple computer supports 14 commands --> we need 4 bits for the control
commands --> opcode = 4 bits

The Address Space in our example simple computer is 2^8 --> we need 8 bits to address
a Memory Word
The number of Data Registers in our example simple computer is 16 --> we need 4 bits
to address a Data Register
An Instruction (Command) may move data between a Memory Address and a Data
Register Address --> we need 8 bits (Memory Address) + 4 bits (Data Register Address) =
12 bits for the Operand
Hence, the Instruction length should be 4 bits (opcode) + 12 bits (Operand) = 16 bits
Because each Instruction should be stored in a Memory Word --> Each Word should fit
the instruction --> Memory word = 16 bits
To make reading an instruction easier, we use Hexadecimal numbers to represent the
binary bits --> 1 Heax = 4 bits

Exercise: Fill in the blanks based on the above table:

The minimum size of the Data Bus should be ............ bits.

The size of the Control Bus should be 4 bits, which can support up to ......... commands.

The minimum size of the Address Bus should be ........ bits, which gives us an address space
of ........... addresses.

If this computer uses isolated memory to address external devices, then we can add up to
....... external devices assuming that we will use the minimal Data, Address, and Control Bus
sizes.

Write the instructions to execute C = A + B (in hexadecimal) knowing that A is located in


Memory Location 40, B is located in Memory Location 41, and C is located in Memory
Location 42.
?
Chapter 6: Computer Networks
‫شبكات الحاسوب‬

In Chapter 1 we Learned

In Von Neuman Model:

Input/Output Data are stored in Memory.

Programs are stored in Memory and coded by


programmers. In Chapter 2 we Learned
Hence ... both Data and Programs should have the
same format: a sequence of 0s and 1s (like The sequence of 0s and 1s (like 01010101101) is in Binary System.
01010101101)
Binary Numbers can get very large and hard to read, so we use Octal or
Hexadecimal Systems to Shorten Binary Numbers.

We can Convert from Binary to Decimal, Octal, and Hexadecimal using


the 2 Exponent Method.

We can Convert between Decimal, Octal, and Hexadecimal by first


converting the number to Binary and then to the desired system.

In Chapter 3 we Learned

We can store Different Data Types in Memory using a Bit Pattern,


which is a sequence of 0s and 1s (like 01010101101) is in Binary System.

We can store Numbers Using: Unsigned, Sign and Magnitude, or 2's


Complement Representation.

We can store Text using some of the well known Encodings like ASCII We can apply different Operations on the Stored Data Types in Memory :
and Unicode. The number of bits needed to represent a language Logical Operations:
depends on the total number of symbols available in that language. Not
AND
We can store Analog Audio by Converting it to Digital Data in Memory OR
using 3 main steps: Sampling, Quantisation, and Encoding. XOR
Shift Operations:
We can store Analog Images by Converting it Digital Data stored using Logical
Raster Method where we use a grid of pixels to represent the original Circular
image. Arithmetic
Left (Multiply)
Also, we can store Simple Images and logos using the Vector method Right (Divide)
where we represent the image using its geometric properties like Arithmetic Operations:
radius and central point. Addition and Subtraction of 2's Complement Numbers
Addition and Subtraction of Sign and Magnitude Numbers
There are two main encodings to represent colors in stored Images: True
Colors - 24 bits and Indexed Colors - 8bits.

Since a Video is a set of continuous Images shown immediately after


each other, we select "Sample" many images from a video clip and call
them Frames and then we store them in Memory as Raster Images.

In Chapter 5 we Learned
The Data Operations are performed in the Computer CPU that includes:
ALU (For Operations)
Data Registers (Fast and expensive to store data near ALU)
Control Unit:
PC (Points at current instruction)
IR (Contain the contents of the current instruction)
The CPU needs to store the Data in the Main Memory which could be:
RAM: SRAM (Faster) or DRAM
ROM (Read-​Only)
Cache Memory is a temporary memory that is faster than RAM but Slower than Data Registers --> it sits between the RAM and CPU
Address Space is the total number of Addresses the RAM can support with a given Addressing Bits
There are many types of Input/Output Devices:
Non-​Storage: like Mouse and Keyboard
Storage:
Magnetic: Like Tape and Disk
Optical: like CD-​ROM, CD-​R, CD_RW and DVD
CPU, Main Memory, and Input/Output Devices are linked by 3 Buses:
Data Bus: Transfers Data, its size >= Memory Word
Address Bus: Transfers the Address of the Memory Location, its size >= Addressing Bits
Control Bus: Transfers the Command to be performed by CPU, its size >= Control Bits
There are two main methods to Address Input/Output Devices:
Isolated memory: Each input/Output device has its own Addressing Bits --> We need to duplicate the Control bits
Mapped-​Memory: One Addressing Space is used for the Main Memory and the Input/Output Devices Memory --> We need to increase the Addressing Bits
We studied a Sample Simple Computer to understand how a computer would execute a Program in the Main Memory.
A Network is a combination of ‫ الشبكة‬Hardware and Software that sends Data
from one location to another.

There are Network Criteria to evaluate the quality of a given Network, it


include:
Performance ‫األداء‬: This could be measured using:
Transit Time: The time it takes to send a signal from one point to
another
Response Time: The time it takes to send a signal and, then receive
a response, from one point to another.
Reliability ‫الموثوقية‬: This could be measured by:
Frequency of failure ‫معدل الفشل‬
Time it takes to recover from failure ‫الوقت المستغرق لتصحيح األخطاء‬
End-​to-​End Encryption:
Robustness in a catastrophe ‫الثبات وقت الكوارث‬
Security ‫األمن‬: This could be measured using:
Protection against unauthorized access ‫الحماية من دخول الغير مخول لهم‬
Protocols to recover from data breeches ‫نظم للتعافي واستعادة البيانات بعد االختراقات‬

A Network could be built using many Topologies ‫بنيات‬. these Topologies would
use the following physical Structures:

Point-​to-​Point Multipoint

Performance: ​ ​Good! Direct link with no congestion

?
Performance: ​ ​Bad! shared links could cause congestion
Security: ​ ​ ​ ​ Fair! Should use techniques like
​ ​ ​ ​ ​ ​ ​ ​ ​end-​to-​end encryption Reliability: ​ ​ ​Bad! if a link in the Middle fails, the whole network fails

?
Reliability: ​ ​ ​ Bad! Single Point of Failure Security: ​ ​ ​ ​Fair! Should use techniques like end-​to-​end encryption

Exercise: Can you improve the above design?

?
Performance: ​ ​Good! Direct link with no congestion

Security: ​ ​ ​ ​Fair! Should use techniques like


​ ​ ​ ​ ​ ​ ​ end-​to-​end encryption
Reliability: ​ ​ ​ Good! If one link fails the other link would work

Cost: ​ ​ ​ ​ ​ ​Bad! Double the cost for extra links


Using the above Physical Structures, we can construct the following
Topologies:

For a Mesh Network: For a Star Network:

Performance: Good! Point-​to-​point Performance: Fair! point-​to-​hub-​to-​point -> congestion at very busy times

?
Reliability: ​ Good! If 1 link fails, there are other links Reliability: ​ Fair! If 1 link fails, only the node connected to this link would fail

?
Security: ​ Fair! It needs proper Security Protocols ​ ​ ​ ​ ​ ​ ​BUT we have a single point of failure: if the Hub fails, the whole
​ ​ ​ ​ ​ ​ network fails
Security: ​ ​ Fair! It needs proper Security Protocols. Plus, there is a Single
​ ​ ​ ​ ​ ​ ​point of failure: if the Hub got hacked, the whole network could
​ ​ ​ ​ ​ ​ ​ be hacked

For a Bus Network

Performance: Poor! Multi-​point link --> congestion at peak time


Reliability: ​ Poor! If 1 link fails, the whole network fails

?
Security: ​ Fair! It needs proper Security Protocols For a Ring Network:

Performance: P ​ oor! Little bit better than the bus


Reliability: ​ ​ Poor! If 1 link fails, the whole network fails

?
Security: ​ ​ ​Fair! It needs proper Security Protocols
Networks Categories

Local-​Area Networks - LAN Metropolitan-​Area Networks - MAN Wide-​Area Networks - WAN

A small network of devices in a local area A Medium network of devices in a A large network in a wide area
like: homes, schools, and workplaces metropolitan area like: city center like: countries or the Internet

An internet means an inter-​connected network: a large network that is made by connecting many other Networks

The Internet (with capital I) is the international network that we all know and use everyday!
A Little Story to explain the TCP/IP Protocol Suite!

Rashid, from Kuwait, wants to send a Message to his friend John in the USA.

Rashid, checks the Yellow Pages to see the Address of John and, then, he puts his Message
inside an Orange Envelope showing John's Address.

,
ck 1
, Blo t 3
USA Slo
e 3,
Hos

John Address: USA, Block 1, House 3

Rashid, puts his Envelope inside his slot in the House Mail Box. Each Slot in this Box is
reserved for one family member.

4
3
2
1

,
ck 1
, Blo t 3
USA lo
3, S
Hose

Slot 1: For Rashid Slot 3: For Sara

Fahad, collects all the Orange Envelops in the House Mail Box that should be sent to the
same Address inside a Purple Envelope.

, ,
ck 1 ck 1 ck 1
,
, Blo t 3 , Blo t 2 , Blo t 4
USA , Slo USA , Slo USA
3 3 Slo
Hos
e
Hos
e e 3,
Hos

USA, Block 1,
Hose 3
Fahad, collects all the Purple Envelopes he has at home and takes them to the Post-​Office.
There, he chooses to send the Envelopes using one of two methods:
1. Fast but not Guaranteed
2. Slow but Guaranteed
USA, Block 1,
Hose 3

Saudi, Block 1,
Hose 3

Bahrain, Block
1, Hose 3

The Post-​Office, check its records and may call nearby airports to confirm the best path
(fastest and not crowded transient airports) to send each Purple Envelope to its final
destination.

USA, Block 1,
Hose 3

Best Path: Turkey - UK - USA

The Post-​Office, put the Purple Envelope inside a Grey Envelope with the Best Path written
on it.

USA, Block 1, Turkey - UK -


Hose 3 USA

The Post-​Office, take all the Grey Envelopes it has to the Airport.

Turkey - UK -
USA

Bahrain -
Oman

Turkey - Spain
- Brazil - Peru
The Airport puts each Grey Envelopes in a Green Envelope indicating the correct Plane that
is going to the next destination written on its Best Path.

Turkey - UK -
Turkey
USA

Bahrain -
Bahrain
Oman

Turkey - Spain
Trukey
- Brazil - Peru

Each Plane takes its Green Envelops to the Airport and, then, the Airport takes them out of
the Green Envelopes before taking them to the local Post-​Office.

Turkey Turkey - UK -
Turkey
USA

Turkey - Spain
Trukey Trukey
- Brazil - Peru

The local Post-​Office takes off the Grey Envelopes to check the written Destination on the
Purple Envelopes. Then, it checks its Records and may call its nearby airports to make sure
each Purple Envelope is traveling on the Best Path. The currently written Best Path may get
changed if the local Post-​Office finds a better Best Path. The Purple Envelopes are then
Placed on new Grey Envelopes and takes them to the Airport.

USA, Block 1,
Hose 3

Best Path: Spain - USA

USA, Block 1,
Spain- USA
Hose 3

The Airport puts each Grey Envelopes in a Green Envelope indicating the correct Plane that
is going to the next destination written on its Best Path.

Spain - USA Spain


.... The Process continues until the Message arrives to its final Destination in the USA.

USA USA USA

The USA Post-​Office would take off the Grey Envelope to check the address on the Purple
Envelope. It would then deliver it to Tom, John's Father

USA, Block 1,
Hose 3

Tom, opens the Purple Envelop and put the Orange Envelopes inside it in the House Mail
Box in the House Mail Box.

USA, Block 1,
Hose 3

4
3
2
1
, ,
ck 1 ck 1 ck 1
,
, Blo t 3 , Blo t 2 , Blo t 4
USA Slo USA Slo USA
e 3, e 3, Slo
Hos Hos e 3,
Hos

Slot 1: For Sally Slot 3: For John

John, takes off the Orange Envelope which Contains Rashid's Message.

How are
you?

,
ck 1
, Blo t 3
USA Slo
e 3,
Hos

If Rashid requested Slow but Guaranteed service:


1. Fahad, Rashid's Father, would wait for a message coming back from John to confirm he
got the Envelope.
2. If Fahad did not get the confirmation Message from John, he would think the Message
did not arrive and he would try to send a new copy to John again.

If Rashid requested Fast but Not Guaranteed service, then Fahad wont wait a
conformation Message!
TCP/IP Protocol Suite TCP/IP ‫حزمة بروتوكوالت شبكة االنترنت‬

There are many protocols that are used to send data in the Internet, we
can divide these protocols into 5 main categories as the following:

,
ck 1
, Blo t 3
USA Slo
e 3,
Hos

4
3
4 2
3 1
,
ck 1
2
USA, Block 1, ,
ck 1
1
, Blo t 3
USA , Blo t 3
3, S
lo
Hose 3 USA lo
,

3, S
USA

Hose
1,
Block

Hose
e 3,
Hos

USA, Block 1, Turkey - UK - USA, Block 1,


Hose 3 USA Hose 3

Turkey - UK -
--- USA
USA

---
Application Layer
Message

Here, a user is trying to send data from an Application on his machine (like .30.9
68.2
IP:1
Internet Browser, Facebook APP, Twitter APP, Whatsup, ..) to the same Application
on another machine URL: [Link]
DNS Server

The user knows the name of the other machine (URL) but he does not know the
URL: Layer 5 Address (Application Address)
Network Address (IP) because it is difficult to remember. Thus, he uses a public
URL IP
service called Domain Name Server (DNS) where he could lookup the Network
Address (IP) of the other Machine by giving its URL Address. [Link] [Link]

[Link] [Link]

When a Packet (Message) enters this layer, it goes with the URL (d5) of the
[Link] [Link]

destination. When the Packet pass this layer, it get IP Address (d3) of the IP: Layer 3 Address (Network Address)

Destination Machine.
Transport Layer ck 1
,
ck 1
, ,
, Blo t 3 , Blo t 2 ck 1
USA USA , Blo t 4
Slo Slo USA Slo
e 3, e 3, e 3,
Hos Hos Hos

Multiplexed Messages Multiplexing


Here, a process-​to-​process delivery of a Message happens (like Whatsup-​to-​ 3
4
1
2
3
4

Whatsup communication). Each Application in the machine has his own Address
.30.9
2
1
68.2 .30.9
IP:1 81 IP:[Link] 68.2
: 80 IP:1 81
,

Port : 80
USA
1,
Block

Port
e 3,
Hos

USA, Block 1,
(Port Number). When a Message pass this layer, it gets the Port Number (s4) of the Hose 3

Source Machine and the Port Number (d4) of the Destination Machine + the IP
Address (d3) of the Destination. Demultiplexing
, ,
ck 1 ck 1 ck 1
,
, Blo t 3 , Blo t 2 , Blo t 4
USA USA

This layer is responsible for the Logical Communication between the two machines.
Slo Slo USA Slo
e 3, e 3, e 3,
Hos Hos Hos

So, there are three methods (Protocols) to manage the communication in this layer:
1. TCP: Slow but Reliable Protocol. Uses Multiplexing (Combining messages to one
destinations together) and Demultiplexing (getting a the individual Message
inside a Multiplexed Packet), Sequence Numbers, Acknowledgement Numbers,
Checksums, and Buffers to make sure the sent messages has arrived to the
destination. If the destination did not send back Acknowledgment Messages, it
will try to send again the messages in the buffer until it gets back the
Acknowledgment Messages. This is best for sending important data.
Destination Port Source Port Destination IP
2. UDP: Fast but Not Reliable Protocol. It Uses Multiplexing and Demultiplexing
but does not require Acknowledgement Messages and does not send back
missing messages to make sure the messages transfer is fast. This is best used
for real life streaming like phone calls or live TV shows.
3. SCTP: A new proposed Protocol that has both advantages of TCP and UDP. It is
still a conceptual Protocol that is not implemented yet.
Network Layer

Here, a Computer-​to-​Computer (or Host-​to-​Host) delivery of Packets happens from


the source to the destination. The Packet may travel through many hosts until it is
Packet
delivered from the source machine to the destination machine.
USA, Block 1, Turkey - UK -

When a Packet pass this layer, it gets (in addition to d4 and s4) the IP Address (d3) Hose 3 USA

of the Destination and the IP Address (s3) of the Source Machine + the IP Address
(n3) of the Next-​Hob (Transit Router).
Best Path: Turkey - UK - USA

The IP Address of the Next-​Hob is calculated based on a Routing Table the


Computer (or Router) maintains with the cost to send a packet to different Hobs.
This Table could be updated using some Protocols (Not part of this course).

This layer relies on the Internet Protocol (IP) to give an Address for each Machine.
There are currently two versions of this Protocol:
IPv4: Used by most current networks. Uses 32 bits for addressing in the Dotted-​
Decimal Notation like the following example:
Destination Port Source Port Destination IP Source IP Next-​Hob IP

​ ​ ​00001010 ​00011001 ​10101100 ​00001111 (32-​Bits Binary)


​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​[Link] (​ 32-​Bits converted to Dotted-​Decimal)

​ T​ he Address Space for IPv4 is ........ ≈ 4 Billions unique Addresses.


​ ​What do you think about this number? .................

IPv6: A newer version that uses 128 bits for addressing. It is being introduced
slowly to current networks and being used at the same time with IPv4. To
represent an IPv6 Address we use a Hexadecimal Notation with 8 groups of 4
Hexadecimal numbers separated by Colon (:) like the following example:

​ ​ ​ ​ ​ ​ ​ ​2001:0db8:0000:0000:0000:8a2e:0370:7334
​ ​(128-​Bits converted to 8 groups of 4 Hexadecimal Numbers separated by : )
Data Link Layer

Here, a Node-​to-​Node (or Hob-​to-​Hob) delivery of Frames happens from the Frame
current node to the next node in the path to the destination.

When a Frame pass this layer, it gets (in addition to d4, s4, d3, and s3) the Data Turkey - UK -
Turkey
USA
Link Address (d2) of the next Node and the Data Link Address (s2) of the Source
Node.

The Data Link Address of the Next-​Hob is could be obtained either Statically
(using local records) or Dynamically (by communicating with other nodes).

The Data Link Address would have different Notations based on the used Protocol
in the Physical Layer to transfer the data (Ethernet, Bluetooth, WIFI, 4G, 5G, ...).
Ethernet: Used by most LAN networks. Uses 48 bits for addressing with a
Hexadecimal Notation with 6 groups of 2 Hexadecimal numbers separated by
Colon (:) like the following example:

Destination Port Source Port Destination IP


​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​07:01:02:11:2C:5B Source IP Next-​Node Data Link Address
Current-​Node Data Link Address

​ ​(48-​Bits converted to 6 groups of 2 Hexadecimal Numbers separated by : )


Turkey

Physical Layer

Here, a Node-​to-​Node (or Hob-​to-​Hob) delivery of Bits on the Physical Medium


happens from the current node to the next node in the path to the destination.
4 4
3 3
2 2
1 1

USA,
1,
Block
3,
Hose
Internet Applications
There are many internet Applications today, some examples are:

Electronic Mail (Email) File Transfer (FTP) Remote Login (Telenet) World Wide Web (WWW)
Electronic Mail (Email)

In the Email Application, one user (Client) can send a message (Email) to another user (Client).

For Example: Alice wants to use her Email Address, Alice@[Link], to send an Email to Bob who
uses the Email Address Bob@[Link].

Alice uses a program on her machine (Message Transfer Agent - MTA) to send the Email to the Server (a
dedicated computer on the network) of her Email Service Provider, [Link]

[Link] receives the Emails from clients like Alice using a program on its server (MTA Server) and
puts all the messages in a Queue ‫طابور‬.

When Alice Email get its turn in the Queue, [Link] send this Email using a program (MTA Client)
through the internet to the Email Server Provider of Bob, [Link] who receives this Email using a
program on its server (MTA Server).

[Link] would put the received Emails in separate folders for each Account.

When Bob connects to the Internet and access his Email account on [Link], he would be notified
that he got a new Email from Alice.

Bob may use one of two protocols to get his emails from Gmail:
1. Post Office Protocol 3, POP3: a simple protocol that delivers the Email as is to the recipient ‫المستقبل‬.
2. Internet Mail Access Protocol, IMAP: a complex protocol that enables the recipient to do many
things with his emails before even downloading them from the server, like: organize his emails into
folders, deleting his Emails, and downloading only part of each Email to preview it before
downloading the whole Email.
An Email Address should start with the name chosen by the Account Owner followed by the symbol @
and finished by the domain name (URL) of the Email Service Provider.

The name chosen by the Email Owner is the name used in the Email Server folder that is assigned for
the Email holder.

Emails are usually sent using ASCII encoding, which can support only plain English letters.

If you need to send text in other languages or to use text formatting or to send multimedia files, then
you need an Optional Protocol called: Multi-​Purpose Internet Mail Extension, MIME.

MIME can convert your non-​ASCII files or texts into ASCII code that is only understandable by MIME.
Hence, the recipient should also use MIME so it can understand the sent Email.
File Transfer (FTP)

This is a protocol that is used to send files from one computer to another.

In this protocol, there are two connections:


1. Control Connection: always open and used so that one computer could agree with another
computer to send him a file
2. Data Connection: always closed unless the two computers agrees to exchange a file, in which case
the data connection would open and the data transfer would take place.
Remote Login (Telenet)

This is a protocol that is used to let a user run application in another computer remotely.

The user would send a command using a Program called Telnet Client to Remote Computer using the
Internet.

The Remote Computer would read the received command using a program called Telnet Server and,
then, execute the received command.
World Wide Web (WWW)

This is the network of all the websites that we visit everyday!

It consists of Hypertext ‫افتراضية‬-‫ نصوص‬and Hypermedia ‫افتراضية‬-‫ وسائط‬that are connected using Hyperlinks
.‫افتراضية‬-‫روابط‬

To access a website we normally use a program called a Browser.

A Browser consists of:


1. Controller to use and understand the correct protocol
2. Interpreters to understand the viewed hypertext and Hypermedia
The most important one is the Hypertext Transfer Protocol, HTTP, that is used to access Hypertext and Hypermedia.

Normally the client user (Browser) would send a request to the computer server that hosts the website. Then the
Server would send back a Response that contains the Hypertext of the page that was sent in the Request.

To access any website using the HTTP Protocol, each website should be addressed using the Uniform Resource
Locator, URL.

The url starts with the Protocol name (Method) followed by :// and then the domain name followed by (optionally) the
port number of the website and then the path of the requested page.

There are three different types of pages on the WWW as following:

Static Pages Dynamic Pages Active Pages

Fixed content that does not change Dynamic content that would return Active content that would return
different results every time a user send different results every time a user
a request to the server interacts with the page without even
sending a new request to the server.

Hypertext is constructed using the Hypertext Markup Language HTML which uses Tags to represent blocks of data as The HTML itself was coded using a more general Markup Language called: Extensible Markup Language, XML.
the following example:
Chapter 7: Operating Systems
‫نظم التشغيل‬

In Chapter 1 we Learned

In Von Neuman Model:

Input/Output Data are stored in Memory.

Programs are stored in Memory and coded by


programmers. In Chapter 2 we Learned
Hence ... both Data and Programs should have the
same format: a sequence of 0s and 1s (like The sequence of 0s and 1s (like 01010101101) is in Binary System.
01010101101)
Binary Numbers can get very large and hard to read, so we use Octal or
Hexadecimal Systems to Shorten Binary Numbers.

We can Convert from Binary to Decimal, Octal, and Hexadecimal using


the 2 Exponent Method.

We can Convert between Decimal, Octal, and Hexadecimal by first


converting the number to Binary and then to the desired system.

In Chapter 3 we Learned

We can store Different Data Types in Memory using a Bit Pattern,


which is a sequence of 0s and 1s (like 01010101101) is in Binary System.

We can store Numbers Using: Unsigned, Sign and Magnitude, or 2's In Chapter 4 we Learned
Complement Representation.

We can store Text using some of the well known Encodings like ASCII We can apply different Operations on the Stored Data Types in Memory :
and Unicode. The number of bits needed to represent a language Logical Operations:
depends on the total number of symbols available in that language. Not
AND
We can store Analog Audio by Converting it to Digital Data in Memory OR
using 3 main steps: Sampling, Quantisation, and Encoding. XOR
Shift Operations:
We can store Analog Images by Converting it Digital Data stored using Logical
Raster Method where we use a grid of pixels to represent the original Circular
image. Arithmetic
Left (Multiply)
Also, we can store Simple Images and logos using the Vector method Right (Divide)
where we represent the image using its geometric properties like Arithmetic Operations:
radius and central point. Addition and Subtraction of 2's Complement Numbers
Addition and Subtraction of Sign and Magnitude Numbers
There are two main encodings to represent colors in stored Images: True
Colors - 24 bits and Indexed Colors - 8bits.

Since a Video is a set of continuous Images shown immediately after


each other, we select "Sample" many images from a video clip and call
them Frames and then we store them in Memory as Raster Images.
In Chapter 6 we Learned

In Chapter 5 we Learned The Network is a combination of Hardware and Software that is used to send information from one point to another.
To evaluate a Network, we use a set of Network Criteria including:
Performance: Transit Time and Response Time
The Data Operations are performed in the Computer CPU that includes:
Reliability: Frequency of failure, Time it takes to recover from failure, Robustness in a catastrophe
ALU (For Operations)
Security: Protection against unauthorized access, Protocols to recover from data breeches
Data Registers (Fast and expensive to store data near ALU)
There are many Network Topologies (Ways to construct a Network), including:
Control Unit:
Mesh: A dedicated link from each point to the other. The best but the most expensive.
PC (Points at current instruction)
Star: A dedicated link from each point to the Hub. The second best with a possible bottle neck and single point of failure.
IR (Contain the contents of the current instruction)
Bus: One link passes through all the points. The worst performance but the cheapest.
The CPU needs to store the Data in the Main Memory which could be:
Ring: Similar to the Bus but it goes in a loop which slightly improves the performance of the bus.
RAM: SRAM (Faster) or DRAM
Networks could be classified as: LAN (local Area - Home or office), MAN (City), WAN (Country or worldwide)
ROM (Read-​Only)
Modern Networks works using the TCP/IP Protocols Suite.
Cache Memory is a temporary memory that is faster than RAM but Slower than Data Registers --> it sits between the RAM and CPU
Address Space is the total number of Addresses the RAM can support with a given Addressing Bits
There are many types of Input/Output Devices:
Non-​Storage: like Mouse and Keyboard
Storage:
Magnetic: Like Tape and Disk
4 4
3 3
2 2
1 1
USA,
1,
Block
3,
Hose

Optical: like CD-​ROM, CD-​R, CD_RW and DVD


CPU, Main Memory, and Input/Output Devices are linked by 3 Buses:
Data Bus: Transfers Data, its size >= Memory Word
Address Bus: Transfers the Address of the Memory Location, its size >= Addressing Bits
Control Bus: Transfers the Command to be performed by CPU, its size >= Control Bits
There are two main methods to Address Input/Output Devices:
Isolated memory: Each input/Output device has its own Addressing Bits --> We need to duplicate the Control bits
Mapped-​Memory: One Addressing Space is used for the Main Memory and the Input/Output Devices Memory --> We need to increase the Addressing Bits There are many Internet Applications, including:
We studied a Sample Simple Computer to understand how a computer would execute a Program in the Main Memory. Email: Using protocols like POP3, IMAP, and MIME.
FTP: To Transfer files between two computers. It uses two connections: Data connection that is usually closed and Control connection that is usually open
Telnet: To control applications on remote computer.
WWW: To access online Hypertext and Hypermedia that are connected using Hyperlinks. It uses the HTTP protocol to manage sent Requests and received
Responses. Websites are built using HTML and the pages are classified as: Static, Dynamic, and Active.
A Von Neumann Computer System consists of 3 Main Components:
1. Hardware (We studied in Chapter 5)
2. Software
a. Application Programs (We studied in Chapter 6)
b. Operating System, OS (we will study in this Chapter) CH. 5

The OS ‫التشغيل‬-‫ نظام‬is a complex software that could be defined as:


1. An Interface between the Hardware and the User (Program or human).
2. A Program (or a set of programs) that facilitates the execution of other
programs.
3. A General Manager supervising the activity of each component in the CH. 7
Computer.
CH. 6
The Major Design Goals of an OS include:
Efficient Use of Hardware ‫للموارد‬-‫األمثل‬-‫االستخدام‬
Ease of Use ‫االستخدام‬-‫سهولة‬

The Bootstrap Process ‫األولي‬-‫التشغيل‬-‫ إجراء‬is an important process that helps the
computer to load the OS in the Memory directly after turning-​on the Computer
Power.

The Bootstrap Program is usually stored in a ROM at the beginning of the


Main Memory Addressing Space.

The Bootstrap Process works as the following:

1. When the Power is turned on, the PC Counter of the CPU would point at
Address 0 which contains the beginning of the Bootstrap Program.
2. The Bootstrap Program run instructions to load the OS in the Main
Memory, RAM.
3. The PC Counter would point at the Loaded OS program and the OS
would start Controlling the Computer.
The Operating System, OS has evolved into many phases as following:

Batch Systems Time-​Sharing Systems Personal Systems Parallel Systems Distributed Systems Real-​Time Systems

Designed in the 1950s. Multi-​Programming: runs many Programs OS designed for Personal Computers Because a Single CPU is not enough for Because even Multi-​Core Systems are not A Real Time System is a system that is
Mono-​Programming: runs only one Program at the same time OLD OS supported only a Single-​User, such modern Applications, we developed Parallel enough for some users, we developed expected to do tasks in specific time
at a time Uses Time-​Sharing where the OS allows each as the DOS OS Systems Distributed Systems using the Networking constraint
Used Punched Cards for input/Output program to use the Computer Resources Most Current OS support Multi-​Users In Parallel Systems, there are Multi-​Core Techniques Real Time Systems are usually used for Real-​
Each Program to be executed was called a Job (CPU) for only a portion of time before (CPUs) that the Applications could share In Distributed Systems, a Programmer send Time Applications that monitors or control
Each Programmer sends a request to a allowing other programs to use those among them so we can truly run many his code to other Machines in the Network External Devices (like cars, washing
Human Operator to run his program resources. applications at the same time (usually a Cloud) so the code would run on Machines, Trains, and so on)
Because CPU is much faster than Humans, we Multi-​Machines at the same time
feel that all the Programs are working at the
same time
The Operating System, OS has the following main components:

User Interface
Memory Manager
Process Manager Device Manager File Manager
Interface accepts Request from Users (Humans or Process)
The Memory Manager decides which process would be loaded into
User Interface

An Interface accepts Request from Users (Humans or Process)


and Interprets them ‫ تترجمهم‬to the rest of the OS components
The User Interface is called Shell in Unix
In other Graphical OS (like Windows and MAC), the interface is
called Window
Memory Manager

The Memory Manager decides which process would be loaded into


Main Memory and how much space it would be given

Monoprogramming Multiprogramming

A small part of the Main Memory is used for the OS A small part of the Main Memory is used for the OS
Most of the Main Memory is used for a Single Program only Most of the Main Memory is used for Many Programs at the
This should mean Faster Processing same time
Running Many Programs at the same time is done using Time
Sharing Techniques where the Programs would take turns to
use the CPU for a small specified amount of time
‫محددة‬-‫قصيرة‬-‫لفترة‬-‫بالدور‬-‫البرامج‬-‫تعمل‬
This should mean Slower Processing compared to
Monoprogramming

Nonswapping Swapping
Nonswapping

The Whole Program ‫البرنامج‬-‫ كامل‬should be loaded in the Main


Memory
Should be Faster than Swapping (less load/save operations with
the hard-​disk)

Partitioning Paging
The Main Memory is divided into Frames of equal size (5 MB
for example)
The Whole Program ‫البرنامج‬-‫ كامل‬should be loaded in the Main
Each Program is divided into Pages of equal size that MUST
Memory in One Partition
equal the chosen size for the Frame
Should be little bit Faster than Paging (less jump operations)
The Whole Program ‫البرنامج‬-‫ كامل‬should be loaded in the Main
However, it could waste more Memory
Memory in Many Pages that are not required to fit next to
each other

page

frame
Swapping

Part of the Program ‫البرنامج‬-‫من‬-‫ جزء‬should be loaded in the Main


Memory
Other Parts of the Program are loaded to the Main Memory
On Demand when they are needed
Should Save more Memory compared to the Nonswapping

Demand Paging Demand Segmentation

The Main Memory is divided into Frames of equal size (5 MB The Program is divided into Logical Segments (Partitions)
for example) where each segment does a specific task --> The code lines in
Each Program is divided into Pages of equal size that MUST each segment are highly related to each other and usually on
equal the chosen size for the Frame demand together
The Part of the Program ‫البرنامج‬-‫من‬-‫ جزء‬should be loaded in the The Some Program ‫للبرنامج‬-‫المنطقية‬-‫األجزاء‬-‫ بعض‬should be loaded in
Main Memory in Many Pages that are not required to fit next the Main Memory in Many Segments
to each other Should be Faster than Paging (less swap operations) but Slower
Should saves more Memory compared to Paging, but would be than Partitioning where there is no swap at all
slower because the Swapping operations from/to Hard-​Disk However, it could waste more Memory
takes long time.
Virtual Memory

Using Swapping Techniques, we can run Multiprograms at one


time, without loading the whole programs in the Main
Memory
This means that we can run Programs with a total size that is
larger than the size of our Main Memory
The size of all the programs that run at a given time in the Main
Memory is called Virtual Memory
Process Manager

The Process Manager manages which process would be using the CPU and
other Hardware Resources and for how much time

In the Machine Cycle, the code has 3 different names depending on its State:

1. Program: when the code is not active and still stored in the Hard Disk
2. Job: when the Program is selected to be executed in the CPU
3. Process: when the Job enters the Main Memory and starts to get turn in
using the CPU and other Resources
In order to organize the execution of the different programs, the Process Manager
needs 2 Schedulers and Several ‫جدولة‬-‫ برامج‬Queues:‫طوابير‬

1. Job Scheduler: labels the chosen programs to be executed as Jobs and puts
them in the Jobs Queue
a. usually the first Job arrived to the Jobs Queue is the first to enter the Main
Memory
2. Process Scheduler: labels the Jobs that enters the Main Memory as Processes
and puts them in the Process Queue
a. Usually the first Process to arrive to the Process Queue is the first to use
the CPU
b. The process that is chosen to use the CPU would be given a limited time
and, then, would be put back at the end of the Process Queue
c. If a Process requires using an external I/O device, then it would be put at
the back of the I/O Queue
d. When the Process finishes using the I/O device, it would be put back at
the end of the Process Queue
e. When the Process finishes all the code it want to execute, it would be
Terminated and gets out of the Main Memory and become again a
Program
Process Synchronization

Normally, a Process would requires access to a resource (File or Device or Special


Process) in order to finish its code. Sometimes, more than one Process needs to get
access to the same resources at the same time. This could lead to several problems
like:

1. Deadlock ‫مسدود‬-‫طريق‬: This problem happens when OS does not put enough
resource restriction ‫ كافية قيود‬to prevent Processes from holding a resource for a
long time.
a. For example: If Process A needs to use File2 to finish his code but he can't
use it because it is used by Process B who can't finish his code and release
File 2 before he get access to File1 which is already used by Process A who
will not release it before he get access to File2!
2. Starvation ‫المجاعة‬: This Problem happens when OS puts too much restrictions to
prevent Processes from holding a resource for a long time.
a. For example, if Process A needs to use Resources File1 and File2, it wont be
allowed to reserve anyone unless it can get access to both of them. So,
when Process B releases File1, Process C would get the priority to use it.
The same for File2. If this continues, Process A would wait for a long time
before it could get access to both File1 and File2 which would cause a
Starvation.
3. To Prevent Deadlock and Starvation, the OS could use a balanced mix of
resources preemption ‫للموارد‬-‫اجباري‬-‫ ترك‬after holding them for a certain time,
giving Priority to certain Processes, using timers, preventing a process from
reserving a resource unless this Process can reserve ALL the Resources it needs.
Device Manager File Manager

The File Manager controls access and use of Files.


The Device Manager (Input/Output Manager) manages access and use of
Input/Output Devices.
Among the tasks performed by the File Manager are:

Among the tasks performed by the Device Manager are:


1. Controls access to files
2. Supervises files creation, deletion, and modifications
1. Monitors every Input/Output Device to make sure it works correctly
3. Controls files naming
2. Maintains the Input/Output Queue (Or maybe many Queues, one for
4. Supervises files storage
each device)
5. Responsible for files archives and backups
3. Controls the Input/Output Devices Access Policies
‫للجهاز‬-‫الوصول‬-‫صالحيات‬-‫و‬-‫االستخدام‬-‫سياسة‬
The Current Main Operating System, OS

Linux Windows
UNIX

Developed in 1969. One of the oldest and used to develop many Developed in 1991 as a free Replica ‫مجانية‬-‫ نسخة‬of UNIX Developed in 1980s
new OS like MAC OS and Android Free and Open Source‫المصدر‬-‫مفتوحة‬-‫مجانية‬ Developed Windows NT (New Technology) to focus on the Security in
Multiuser, Multiprocessor, and Portable Very popular with many variations in the market the 2000s
Supports programming, Text Editing, communication, and The main components include:
almost anything required by a modern computer user! Environmental Subsystems: Interfaces for different user
The components of UNIX include: groups
Shell: User Interface Executive Layer: Accessible by the computer Admin only. It
Utilities: Programs that come by default with the OS contains critical software like: Input/Output Manager, Process
Application Programs: Programs installed by the Users manager, Security Monitor, and Virtual Memory Manager
Kernel: the core of the OS that manage main tasks like Kernel: contains the core code for the OS
Memory and Process Management Hardware Abstraction Layer (HAL): contains an interface
between the OS and the Hardware

You might also like