0% found this document useful (0 votes)
14 views29 pages

CSE031.Lecture 02.data Representation - Part I

Uploaded by

Bishoy Emad
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)
14 views29 pages

CSE031.Lecture 02.data Representation - Part I

Uploaded by

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

Computer and Systems Engineering Department

Ain Shams University, Cairo, Egypt


• Most operating systems and programming
languages assume that experienced users are
familiar with how information is stored in a
computer. Without this knowledge, nothing
but very basic use of a computer is possible. It
would be also impossible to understand many
of the fundamental design concepts of digital
computers.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
How is data represented in a computer?
Computer systems operate using two voltage levels
(usually 0v and +5v). With two such levels, we can
represent exactly two different values, zero and one.
All kinds of information processed by the computer
are expressed using only these two values.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
1,10, 100
!!!
WHY ?
4 5 6
100 10 1

400 + 50 + 6
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
Decimal Numbering
0–1–2–3–4–5–6–7–8–9
10 digits
Weight: 100 - 101 - 102 - 103 - 104 - …
Weight: 1 - 10 – 100 - 1000 - 10000 - ...

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
Example 3459
= 9×1 =9
+ 5 × 10 + 50
+ 4 × 100 + 400
+ 3 × 1000 + 3000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
Decimal(10) Binary(2)
Number of digits 10 2

Symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 0, 1

Weights 100 , 101 , 102 , 103 , … 20 , 21 , 22 , 23 , …

1, 10, 100, 1000, …. 1, 2, 4, 8, 16,….

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
Example (1010)10 , (1010)2

1000 100 10 1

1 0 1 0 1000+10
one thousand and ten

8 4 2 1

1 0 1 0 8+2 → 10
ten
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
(13)10 = (?)2
8 4 2 1

13 ≥ 8 5≥4 1≥2 1≥1


Yes Yes No Yes
13-8=5 5-4=1 1 1-1=0

1 1 0 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
(6)10 = (?)2
8 4 2 1

6≥8 6≥4 2≥2 0≥1


no Yes Yes No
6 6-4=2 2-2=0 0

0 1 1 0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
(13)10 = (?)2
13= 8+4+1 → (1101)2
13/2 = 6 remainder 1
6/2 = 3 remainder 0
3/2 = 1 remainder 1 (1 1 0 1)2
1/2 = 0 remainder 1

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
(52)10 = (?)2
52= ?+?+..+? → (?)2
52/2 = 26 remainder 0
(110100)2
26/2 = 13 remainder 0
13/2 = 6 remainder 1 check
6/2 = 3 remainder 0 1 1 0 1 0 0
32 16 8 4 2 1
3/2 = 1 remainder 1
32+16+4 →52
1/2 = 0 remainder 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
Number Decimal(10) Binary(2) Hexadecimal(16)
of digits 10 2 16
0, 1, 2, 3, 4, 0, 1, 2, 3, 4,
Symbols 0, 1 5, 6, 7, 8, 9, A, B,
5, 6, 7, 8, 9
C, D, E, F

Weight 100 , 101 , 102, … 20 , 21 , 22 , … 160 , 161 , 162 , …

1, 10, 100, …. 1, 2, 4, 8, …. 1, 16, 256, ….

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
(5378)10 = (?)16
5378= ?+?+..+? → (?)16
5378/16 = 336 remainder 2
(1502(
336 /16 = 21 remainder 0
21/16 = 1 remainder 5 check
1/16 = 0 remainder 1 1 5 0 2
163 162 161 160
4096 + 5*256 + 2*1 → 5378
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
(7739)10 = (?)16
7739= ?+?+..+? → (?)16
7739/16 = 483 remainder 11→ B
(1E3B(
483 /16 = 30 remainder 3
30/16 = 1 remainder 14→ E check
1/16 = 0 remainder 1 1 E 3 B
163 162 161 160
4096 + 14*256 + 3*16+ 11*1 → 7739
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
• In general, we can have numbering systems of
any base b, where the digits can be from 0 to
b-1.
• A number dndn-1…d1d0 (where the right most
digit is digit number 0 and the number
increases as we go to the left) in base b, has a
decimal value of
• 𝑑𝑛−1 × 𝑏 𝑛−1 + ⋯ + 𝑑1 × 𝑏 + 𝑑0
= σ𝑛−1𝑖=0 𝑖𝑑 × 𝑏 𝑖
.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
• How many different binary values can be
represented using n bits ?
• 1 bit → 0, 1 → 2 values
• 2 bits → 00, 01, 10, 11 → 4 values
• 3 bits → 000, 001, 010, 011, 100, 101, 110, 111 → 8 values

1 bit → 2 values
2 bits → 4 values
3 bits → 8 values

n bits → 2n values

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
Decimal Binary
• Using n=4-bits 0 0000
1 0001
• 2n= 24= 16 numbers 2 0010
3 0011
Minimum value = 0000 → 0 4 0100
Maximum value = 1111 → 15 5 0101
6 0110
7 0111
8 1000
9 1001
10 1010
11 1011
12 1100
13 1101
14 1110
15 1111

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
Decimal Binary Hexadecimal
(7739)10 = (1E3B)16=( ? )2 0 0000 0
1 0001 1
2 0010 2
3 0011 3
(1) → (0001) 4 0100 4
(E) → (1110) 5 0101 5
6 0110 6
(3) → (0011) 7 0111 7
(B) → (1011) 8 1000 8
9 1001 9
10 1010 A
(1E3B)16=( 0001 1110 0011 1011)2 11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F
Check → (20+ 21+ 23)+( 24+ 25)+( 29+ 210+ 211)+ (212)
= (1+2+8)+(16+32)+(512+1024+2048)+(4096) = 7739
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
How many bits would you need to address 1000 location(byte) ?

9 bits → 29 → 512 locations


10 bits → 210 → 1024 locations
1000 locations → at least(10 bit)

Memory with 10 bit address line → 1024


locations(byte) → about 1K byte
First address (0000000000)2= (0)16
Last address (1111111111)2=(3FF)16

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
345.678
100 10 1 0.1 0.01 0.001
102 101 100 10-1 10-2 10-3

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
(101.101)2

22 21 20 2-1 2-2 2-3


4 2 1 1/2 1/4 1/8
(101.101)2= (4+1+0.5+0.125)10= (5.625)10
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
(0.6875)10 = (?)2
0.6875= 0.5+0.125+0.0625 → (0.1011)2
2-1 2-3 2-4
0.6875 * 2 = 0.3750 Overflow 1
0.3750 * 2 = 0.7500 Overflow 0
0.7500 * 2 = 0.5000 Overflow 1 (0.1011)2
0.5000 * 2 = 0.0000 Overflow 1

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
1

8 4 7
6 8 2
1 5 12 9
2
1529

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
weight 4 2 1

1 0 1 →5
0 1 0 →2
1 1 1 →7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
1 1

1 1 1 →7
1 1 0 →6
(3)10 (2)10 1
(11)2 (10)2
1 1 0
1 1 0 1 → 13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
(5 8 4)16
(7 1 9)16
(12)10 (9)10 (13)10
(C)16 (9)16 (D)16
(C 9 D)16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
1
(5 8 A)16
(B 4 9)16
(16)10 (13)10 (19)10
(10)16 (D)16 (13)16
(3)16
(10D3)16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
Thank you
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

You might also like