CSE031.Lecture 02.data Representation - Part I
CSE031.Lecture 02.data Representation - Part I
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
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
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
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
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) ?
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
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