103 Introduction
103 Introduction
What is a Computer?
Input Output
What is a Computer?
Program
Input Output
Program
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.
!
g Machine
e of a Turin
urate pictur
A more acc
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
Could use
Distributed
computing "On
the Cloud"
Privacy
Isuues!!
Issues Related to Computers
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
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?!
But HOW can we know the number of digits (binary or octal or hexadecimal) we need to
convert a Decimal number?
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
Hexadecimal, Base 16
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
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
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
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
1 _ _ _ _ _ _
Binary (So far) (1 * 64) = 64
1 0 _ _ _ _ _
Binary (So far) (1 * 64) + (0*32) = 64
1 0 0 _ _ _ _
Binary (So far) (1 * 64) + (0*32) + (0 * 16) = 64
1 0 0 1 _ _ _
Binary (So far) (1 * 64) + (0*32) + (0 * 16) + (1 * 8) = 72
1 0 0 1 0 _ _
Binary (So far) (1 * 64) + (0*32) + (0 * 16) + (1 * 8) + (0 * 4) = 72
1 0 0 1 0 0 _
Binary (So far) (1 * 64) + (0*32) + (0 * 16) + (1 * 8) + (0 * 4) + (0 * 2) = 72
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
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
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 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
Octal are used in Older Systems while Hexadecimal is used in Modern Systems.
Converting
Hexa, base 16
x
using Exponent Method (2 )
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
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
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
4 1 _ _
Binary (So far) (1 * 4) = 4
3 Digits
2 1 0
2 2 2 1 0 _
Binary (So far) (1 * 4) + (0*2) = 4
4 2 1
1 0 0
Binary (So far) (1 * 4) + (0*2) + (0 * 1) = 4
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
1 _ _
Binary (So far) (1 * 8) = 8
_ _ _
1 0 1 0
Binary (So far) (1 * 8) + (0*4) + (1 * 2) + (0 * 1) = 10 (--> A)
1 _ _
Binary (So far) (1 * 8) = 8
_ _ _
1 1 1 0
Binary (So far) (1 * 8) + (1*4) + (1 * 2) + (0 * 1) = 14 (--> E)
(using Binary)
Octal, base 8 Decimal, base 10
Hexa
A E
4 Digits 4 Digits
_ _ _ _ _ _
8 4 2 1 8 4 2 1
1 0 1 0 1 1 1 0
Binary 1 0 1 0 1 1 1 0
128 64 32 16 8 4 2 1
Hexa
A E
4 Digits 4 Digits
_ _ _ _ _ _
8 4 2 1 8 4 2 1
1 0 1 0 1 1 1 0
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
0 0 . 1
0 0
numbers?!
Binary 1 0 1 . 1 1
4 2 1 . 0.5 0.25
_ _ _ .
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
In Chapter 1 we Learned
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:
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
0 0 0 1 0 0 1
64 32 16 8 4 2 1
But, what would happen if we try to Store a large Number that needs more digits than the
available bits in Memory?
1 0 0 1
!
8 4 2 1
re
o sto
et
ac
sp
No
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
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:
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:
1 0 0 1 0 1 0 1
- 64 32 16 8 4 2 1
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!
1 0 0 1
8 4 2 1
The stored number now is: - 1 instead of 9!
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
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.
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
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).
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
1 0 0 1 0 1 0 0
- 1 1 0 1 1 0 0
- 64 32 16 8 4 2 1
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!
1 0 0 1
- 4 2 1
The stored number now is: - 7 instead of 9!
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
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.
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?
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
7
Max = (2)
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
Unlike Numbers and Text which are Discrete "Digital" Data, Audio is Continuous
"Analog" Data
Sound
Grade
Intensity
100 65 80
Sampling
Sampling
Sampling
S = Number
of Samples
per Second
Quantization
-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
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
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 d for not good for basic images, diagrams, logos, and professional drawing because
it is hard to retain the quality if scaling is needed.
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
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
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.
In Chapter 3 we Learned
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.
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.
Data
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
عكس
االثنين معا- مع أحد العناصر أو كالهما معا-أو أحد العناصر فقط وليس كالهما- أو الحصرية
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
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
3. The sentence "Please khalid, buy for me both chicken and beef sandwiches,
I am hungry!" can be represented using:
4. The sentence "Please khalid, only buy for me a beef sandwich, I do not like
chicken!" can be represented using:
?
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 =
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 ________________
?
XOR
?
AND mask 11100011 mask 11100011
?
mask 00011100
11111011
Result Result 01111011
Result 00011000
Shift
Operations
عمليات اإلزاحة
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
?
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
? ?
10011100 11100111
Note: Note:
input 01111111
00000010
?
Note:
00000010 in Decimal = -2
We got an overflow!
Arithmetic
Operations
العمليات الحسابية
Then, we will write the sum result and the carry for
the next bit on the left:
2's
(B + 1) 10100101
Complement
Carry 0011010
?
A 10011010 -102 (A + 1) 0 1 1 0 0 1 1 0 -102
+
B 01011011 91
B 00011010 26
+
Carry
(B + 1)
A
1111110
10011010
11100110
? -102
-26
A 10011010 B 01011011
B 01011011 91
-
?
Carry 1111110
91
B 01011011
+
(A + 1) 01100110 102
We got an Overflow!
?
7 7
-2 , 0 , 2 - 1
-128, 0 , +127
Arithmetic
Operations
العمليات الحسابية
No need to
memorize this
chart, I will
give it to you
in the exam :)
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!
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
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
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 Chapter 3 we Learned
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.
Program
Input/Output Data
Input/Output Data
Program Memory
Memory
Memory
RAM - Random Access Memory
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
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
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
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.
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!
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
For Computers
4000 M^2
The Total Area is -> Memory Size
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:
Address
Address Address
00 2-Bytes
8 Bytes 01 2-Bytes
000 1-Byte 1-Byte 100
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?
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
ممغنطة ضوئية
SSD
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
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:
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
Read 00
Answer: Read 00
#Symbols = 4 Answer:
Data Bus Size = Write 01
#Symbols = 4
Data Bus Size = Write 01
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
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.
In Chapter 1 we Learned
In Chapter 3 we Learned
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.
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.
A Network could be built using many Topologies بنيات. these Topologies would
use the following physical Structures:
Point-to-Point Multipoint
?
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
?
Performance: Good! Direct link with no congestion
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
?
Security: Fair! It needs proper Security Protocols For a Ring Network:
?
Security: Fair! It needs proper Security Protocols
Networks Categories
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
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
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
The Post-Office, put the Purple Envelope inside a Grey Envelope with the Best Path written
on it.
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
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.
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
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 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
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
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
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
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
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:
Physical Layer
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.
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)
It consists of Hypertext افتراضية- نصوصand Hypermedia افتراضية- وسائطthat are connected using Hyperlinks
.افتراضية-روابط
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.
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 Chapter 3 we Learned
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.
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
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.
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
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
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
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
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
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
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