Lecture 2 - 3number System
Lecture 2 - 3number System
Data
Representation
Department of Computing
Shifa Tameer-e-Millat University
(STMU). 1
Digital Data Representation
A well known example of digital data is finite integer representation using Decimal Number
system
Decimal Number System
It has Base 10
A number base is the total number of digits that a system of counting uses to
higher numbers
Decimal number system contains 10 numbers (0,1,2,…, 9) that are used to
represent any other number
Decimal number system is a positional number system in which every
number greater
than 9 is represented as sum of products
2
Number System
3
Introduction
4
Number System
Decimal system uses 10 symbols
(digits)
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Octal System uses eight symbols
0, 1, 2, 3, 4, 5, 6, 7
Binary System uses only two
symbols
0 and 1
Hexadecimal System uses sixteen
symbols
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E,
F
• Base (radix) = 10
– 10 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8,
9 } Position
• Digit 2 1 0 -1 -
– Integer & fraction 2
4 1 5 4 4
• Digit Weight
100 10 1 0.1 0.01
– Weight = (Base) Position
3 5 0 1 . 5 1
digit
Most Least
Significant decimal Significant
Digit point Digit 7
Binary Number System
• Base (radix) = 2
– 2 digits { 0, 1 }, also called
“bits”
• Weights 4 2 1 1/2 1/4
– Weight = (Base) Position 1 0 1 0 1
– Weight = (2) Position
2 1 0 -1 -2
• Magnitude
1 *22+0 *21+1 *20+0 *2-1+1 *2-2
– Sum of “Bit x Weight”
=(5.25)10
• Formal Notation
(101.01)2
• Groups of bits
– 4 bits = Nibble {1 0 1 1}
– 8 bits = Byte {1 1 0 0 0 1 0 1}
– 16 bits = {1 1 0 0 0 1 0 1 1 1 0 1 0 1 0
Word 0} 8
Binary System
1 1 0 1 . 0 1
bit
Most Least
Significant binary Significant
Bit point Bit 9
Octal Number System
• Base (radix) = 8
– 8 digits { 0, 1, 2, 3, 4, 5, 6, 7 }
• Weights 64 8 1 1/8 1/64
10
Hexadecimal Number System
• Base (radix) = 16
– 16 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E,
F}
256 16 1 1/16 1/256
• Weights
– Weight = (Base) Position
11
Number Systems
• Decimal Numbers Decimal Binary Octal Hex
– 10 Digits 00 0000 00 0
• Binary Numbers 01 0001 01 1
02 0010 02 2
– 2 Digits/Bits
03 0011 03 3
• Octal Numbers 04 0100 04 4
– 8 Digits 05 0101 05 5
06 0110 06 6
• Hexadecimal
07 0111 07 7
Numbers 08 1000 10 8
– 16 Digits 09 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
12
Familia
r
Octal System Hexa decimal Decimal Binary
System
Base 4 number
(Base – 8 ns) Number Number Equivalent System
System (Base (Base-10) (Base-2) (Base -4)
– 16)
0 0 0 0 0
1 1 1 1 1
2 2 2 10 2
3 3 3 11 3
4 4 4 100 10
5 5 5 101 11
6 6 6 110 12
7 7 7 111 13
10 8 8 1000 20
11 9 9 1001 21
12 A 10 1010 22
13 B 11 1011 23
14 C 12 1100 30
15 D 13 1101 31
16 E 14 1110 32
17 F 15 1111 33
Number Systems
Decimal 10 0,1,2,…,9
Binary 2 0,1
Octal 8 0,1,2,…,8
Hexadecimal 16 0,1,..9,A,B,C,D,E,F
14
Bits, Bytes, Nibbles
byte
Bytes & Nibbles
🞑 Byte (B) = 8 bits 10010110
nibble
Used everyday
🞑 Nibble (N)
= Not
4 bits
commonly used CEBF9AD7
most least
significant significant
byte byte
15
KB, MB, GB …
3501 (base-10)
1 X 100 = 1
0 X 101 = 0
5 X 102 = 500
3 X 103 = 3000
17
Binary-to-Decimal Conversion
1101 (base-2)
1 X 20 = 1
0 X 21 = 0
1 X 22 = 4
1 X 23 = 8
8 + 4 + 0 + 1 = 13
11012= 1310
18
Digital Data Representation
Binary to Integer Number Conversion
100112 = (?)10
= (1 x 24) + (0 x 23) + (0 x 22) + (1 x 21)+ (1 x 20)
= (1 x 16) + (0 x 8) + (0 x 4) + (1 x 2) + (1 x 1)
= 16 + 0 + 0 + 2 + 1
= 1910
19
Octal-to-Decimal Conversion
5217 (base-8)
7 X 80 = 7x1 = 7
1 X 81 = 1x8 = 8
2 X 82 = 2x64 = 128
5 X 83
= 5x512 = 2560
2560 + 128 + 8 + 7 = 2703
52178 = 270310 20
Hexadecimal-to-Decimal Conversion
192
10 X 162
=10x256 =
21
2560
Binary to Octal Conversion
• Each of 3 binary Octal Binary
represent
group an octal
bitsdigit
0 000
• Starting from fractional
point combine binary bits in group 1 001
of 3 2 010
Assume Zeros
Example:
3 011
( 1 0 1 1 0 . 0 1 )2 4 100
5 101
6 110
( 2 6 . 2 )8 7 111
8 X 10-2 = 8x0.01 =
0.08
1 X 10 -3 =
1x0.001 = 0.001
24
Binary-to-Decimal
Conversion
.101 (base-2)
1 X 2-1 = 1x0.5 =
0.5
0 X 2-2
= 0x0.25 = 0
1 X2 -3 =
1x0.125 = 0.125
0.1012 = 0.62510
25
Octal-to-Decimal
Conversion
.25 (base-8)
2 X 8-1 = 2x0.125 =
0.25
5 X 8-2 =
5x0.015625 =
0.017825
0.258 = 0.26782510
26
Hexadecimal-to-Decimal
Conversion
. F5 (base-16)
15 X16-1
= 15x0.0625 =
0.9375
5 X16-2
= 5x0.00390625
= 0.01953125
= 16 + 8 + 4+ 0
+ 0 + 0.5 + 0 + 28
Number Base Conversions : Practice Questions
29
Decimal-to-Binary Conversion(positional
number)
250 25010 = 1 1 1 1 1 0 1 02
2 250 Remainder
2 125 Remainder
0
2 62 1
2 31 0
Remainder
2 15 Remainder 1
1
2 7
Remainder
Remainder 1
2 3
Remainder 1
1
30
Decimal to Binary Conversion
Answer: = (0.001)2
31
Decimal-to-Octal
Conversion
250
8
8 31 Remainder 2
250 3 Remainder 7
25010 = 3728
32
Decimal-to-Hexadecimal
Conversion
250
16 250
15 Remainder 10
25010 = 15 1016 ?
= FA16
33
Decimal-to-Binary Conversion(fractional
number)
0 . 4375
0.4375 x 2 = 0.8750
0.8750 x 2 = 1.75
0.75 x2 = 1.5
0.5 x2 = 1.0
0.437510 = 0.01112
34
Decimal-to-Octal
Conversion
0 . 4375
0.4375 x 8 = 3.5
0.5 x8 = 4.0
0.437510 = 0.348
35
Decimal-to-Hexadecimal
Conversion
0 . 4375
0.4375 x 16 =
7.0
0.437510 = 0.716
36
Example :Decimal-to-Binary
Conversion(Estimation)
0.782 110012 2-1 + 2-2 + 2-5
0.5 + 0.25
0.782 x 2 = 1.564
+0.03125
0.564 x 2 = 1.128
0.78125
0.128 x 2 = 0.256
0.256 x 2 = 0.512 11001000012
0.512 x 2 = 1.024 2-1 + 2-2 + 2-5 + 2-10
0.024 x 2 = 0.048 0.5 + 0.25 +0.03125 +
0.048 x 2 = 0.096 0.0009765625
0.192 x 2 = 0.384 0.7822265625
0.384 x 2 = 0.768
0.768 x 2 = 1.536
37
Decimal to Octal Conversion
39
Number Base Conversions : Practice Questions
40
Exercise
2
Convert these c)
system decimal (22.5)10=( ? )2
system numbers
numbers to
a) 17 binary 2222
11
b)38 0
c)22.5 2 5 1
d)
2 2 1
764.3
75 1
0
0.5 x 2 = 1.0
=> (22.5)10=(
10110.1 )2 41
Base X– to – Base Y
Conversion
We can convert base x number to base y
number by following these steps :
🞑 Convert base x to base 10 (decimal system
number)
🞑 Then, convert decimal number to base y
42
Number Base Conversions
Sum of
(Digit x Weight)
Octal
(Base
8)
Sum of
(Digit x Weight)
?
Decimal Binary
(Base (Base
10) 2)
Hexadecimal
(Base 16)
9/16/2020
23 43
Octal to Hexadecimal
• Convert to Binary as an intermediate step i.e.
Convert from Octal to Binary to Hexadecimal
Example: ( 2 6 . 2 )8
( 0 1 0 1 1 0 . 0 1 0 )2
(1 6 . 4
)16
Works both ways (Octal to Hex & Hex to Octal)
44
Exampl
e
Convert 372.348 to hexadecimal system
number
🞑 Convert 372.348 to decimal system number
372.348 = (3x82)+(7x81)+(2x80) . (3x8-1) + (4x8-2)
= 192 + 56 + 2 . 0.375 + 0.0625
= 250 . 4375
🞑 Convert 250.437510 to hexadecimal system
number
250 / 16 = 15 remainder 10
250.4375 0.4375 * 16 = 7.0
10
250 number
Positional FA16 0.4375 0.716
Fractional number
372.348 = FA.716 45
Exercise 3 (TODO)
46
Number Base Conversion :
Binary, Octal, Hexadecimal to Decimal
• For Base Conversion from Binary, Octal and
Hexadecimal to Decimal use the Sum*Weight
formula
d *B 2+d *B 1+d *B 0 + d *B-1 +d *B-2
2 1 0 -1 -2
Integer Part
Fractional Part
4
1 *2 +0 *2 +1 *2 +0 *2 +1 *2
4 3 2 1 0
2
1
=(21)10
47
Number Base Conversion
(Decimal to Binary, Octal, Hexadecimal)
50
Reading Assignment
• Read the following topics from Chapter 1 of
the
book
– 1.2 : Number systems
– 1.3 : Number base conversion
– 1.4 : Octal and Hexadecimal Numbers
51