0% found this document useful (0 votes)
2 views50 pages

Lecture 4- Number System - Copy

The document provides an overview of various number systems used in digital data representation, including decimal, binary, octal, and hexadecimal systems. It explains the base, symbols, and conversion methods between these systems, highlighting their significance in computing. Additionally, it discusses the concepts of bits, bytes, and data storage units like KB, MB, and GB.

Uploaded by

junaid.ssc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views50 pages

Lecture 4- Number System - Copy

The document provides an overview of various number systems used in digital data representation, including decimal, binary, octal, and hexadecimal systems. It explains the base, symbols, and conversion methods between these systems, highlighting their significance in computing. Additionally, it discusses the concepts of bits, bytes, and data storage units like KB, MB, and GB.

Uploaded by

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

Data Representation

Instructor: M.Junaid Khattak

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
Introduction

 Many number systems are in use in


digital technology. The most
common
• Decim are (Base
:
al 10)
• Binary (Base 2)
• Hexadecimal
• Octal (Base 8)16)
(Base

• The decimal system is the number


system that we use everyday

3
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

to represent any number, no matter how large 4


Decimal Number System

• Base (radix) = 10
– 10 digits { 0, 1, 2, 3, 4, 5, 6, 7, 8,
9 } Position
• Digit 2 1 0 -1 -2
– Integer & fraction
4 1 5 4 4
• Digit Weight
100 10 1 0.1 0.01
– Weight = (Base) Position

– Weight = (10) Position


• Magnitude
400 10 5 0.4 0.04
– Sum of “Digit x Weight”
d2*B2+d1*B1+d0*B0+d-1*B-1+d-2*B-2

• Formal (415.44)10
Notation
5
Decimal System

 The decimal system is composed of 10 numerals or


symbols. These 10 symbols are 0,1,2,3,4,5,6,7,8,9;
using these symbols as digits of a number, we can
express any quantity.
 Example : 3501.51

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 = {1 0 1 1}
Nibble {1 1 0 0 0 1 0 1}
– 8 bits = Byte {1 1 0 0 0 1 0 1 1 1 0 1 0 1 0
– 16 bits = 0} 8
Binary System

 The binary system is composed of 2 numerals or


symbols 0 and 1; using these symbols as digits
of a number, we can express any quantity.
 Example : 1101.01

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} 64 8 1 1/8 1/64
• Weights
5 1 2 7 4
– Weight = (Base) Position
2 1 0 -1 -
– Weight = (8) Position 2

• Magnitude 5 *82+1 *81+2 *80+7 *8-1+4 *8-2


– Sum of “Digit x Weight” =(330.9375)10
• Formal (512.74)8
Notation

9
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

– Weight = (16) Position 1 E 5 7 A


• Magnitude 2 1 0
-1 -2
– Sum of “Digit x Weight”
1 *162+14 *161+5 *160+7 *16-1+10 *16-2
=(485.4765625)10
• Formal
Notation (1E5.7A)16

10
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
11
Familiar
System
Octal System Hexa decimal Decimal Binary Base 4
(Base – 8 ns) Number Number Equivale number
System (Base (Base- nt (Base- System
– 16) 10) 2) (Base -4)
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

Number System Base Possible Digits

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

13
Bits, Bytes, Nibbles

 Bits 1001011
(b) 0
most least
significan significan
t bit t bit

byt
 Bytes & Nibbles e

Byte (B) = 8 bits 1001011


 Used everyday 0 nibbl
e

Nibble (N) = 4
 bits
Not commonly CEBF9AD
used 7
most least
significa significa
nt byte nt byte
14
KB, MB, GB …

 In computer, the basic unit is byte (B)


 And, we use KB, MB, GB many many many
times
210 = 1024 1KB
1024 x (kilobyte)
2=20 = 1MB
1024
2 1024 x 1024 x (megabyte)
=
30 = 1GB
1024= (gigabyte)
 1TB these?
How about
240
(terabyte)
= 1PB
(petabyte)
250
1EB
=
(exabyte) 15
60
Decimal Number Quantity (positional number)

 350 (base-
1 10)
1 X 100 1
=
0 X

101
= 0
5 X

102
16
=
Binary-to-Decimal Conversion

 110 (base-
1 2)
1 = 1

X = 0
= 4
20
= 8
0

X
17
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

18
Octal-to-Decimal Conversion

 521 (base-
7 8)
7 = 7x1 =X 870

1 = 1x8 =X 881
2 = 2x6 =X 128
82
4
5 X 83
= 5x512 = 2560
2560 + 128 + 8 + 7 = 2703
52178 = 270310 19
Hexadecimal-to-Decimal Conversion

 1AC (base- [ A = 10, B= 11, C = 12, D = 13, E= 14,


F= 15 ]
F 16)
15 X =15x1 = 15
160
12 X =12x16 = 192
161
110XX
163=10x25 = 2560
=
162 6=
5x4096
20480
20480 + 2560 +192 + 15 = 23247
20
Decimal Number Quantity (fractional
number)
 .58 (base-
1 10)
5 X 10- = =
1 5x0.1 0.5
8 X 10-2 =
8x0.01 = 0.08
1 X 10-3 =
1x0.001 = 0.001

0.5 + 0.08 + 0.001 = 0.581


21
Binary-to-Decimal Conversion

 .10 (base-
1 2)
1 X 2- = =
1 1x0.5 0.5
0 X 2-2 =
0x0.25 =0
1 X 2-3 =
1x0.125 = 0.125

0.5 + 0 + 0.125 = 0.625

0.1012 = 0.62510 22
Octal-to-Decimal Conversion

 .2 (base-
5 8)
2 X 8- = =
1 2x0.125 0.25
5 X 8-2 =
5x0.015625 =
0.017825

0.25 + 0.017825 = 0.267825

0.258 = 0.26782510
23
Hexadecimal-to-Decimal Conversion

 . F (base-
5 16)
15 X16-1

= 15x0.0625 =
0.9375
5 X16-2

= 5x0.00390625
= 0.01953125

0.9375 + 0.01953125 = 0.95703125 24


Binary to Octal Conversion

• Each of 3 binary bits Octal Binary


represent
group an octal digit
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

Works both ways (Binary to Octal & Octal to Binary)


25
Binary to Hexadecimal
• 16 = 24 Hex Binary
0 0000
• Each group of 4 bits 1 0001
represents a hexadecimal digit 2 0010
3 0011
Assume Zeros 4 0100
Example: 5 0101
6 0110
( 1 0 1 1 0 . 0 1 )2 7 0111
8 1000
9 1001
A 1010
B 1011
(1 6 . 4 C 1100
)16 D 1101
E 1110
Works both ways (Binary to Hex F 1111
&
33 23
Hex to Binary)
Exercise 1
 Convert these binary system numbers to
decimal system numbers
a) 100101101
b)
11100.1001
c)111111
d)100000.0
111
 b)
1x24 + 1x23 +
1x22 + 0x21 +
0x20 + 1x2-1 +
0x2-2 + 0x2-3 1+
1x2-4 27
Number Base Conversions : Practice Questions

• Convert the following from Binary to Decimal

–(101)2 , (11001)2 , (11100)2 , (11.010)2

• Convert the following from Octal to Decimal

–(17)8 , (76)8 , (236)8 , (35.25)8

• Convert the following from Hexadecimal to Decimal

–(7A)16 , (78F)16 , (109B)16 , (50.1C)16

28
Decimal-to-Binary Conversion(positional number)

 25 25010 = 1 1 1 1 1 0
0 2 1 02
250 Remainder
Remainder 0
22 1
Remainder
125
62
2 0
Remainder
31 1
Remainder 1
22 15
7
Remainder 1
2 3
1 Remainder 1

29
Decimal to Binary Conversion

Example (Integer) : (13)10


Quotient Remainder Coefficient
13/ 2 = 6 1 a0 = 1
6/2= 3 0 a1 = 0
3/2= 1 1 a2 = 1
1/2= 0 1 a3 = 1

Answer: (13)10 = (a3 a2 a1 a0)2 =


(1101)2

Example (Fractional) : ( 0.125 )10

Answer: = (0.001)2
30
Decimal-to-Octal Conversion

 25
0 8
250 Remainder 2
8 3 Remainde 7
31 r
25010 =
3728

31
Decimal-to-Hexadecimal Conversion

 250
16
1 Remainde 1
250 5 r 0

25010 = 15
1016 ?
= FA16

32
Decimal-to-Binary Conversion(fractional
number)
 0.
4375
0.4375 x 2 = 0.875
0
0.8750 x 2 = 1.75
0.75 x 2 = 1.5
0.5 x2 = 1.0

0.437510 =
0.01112

33
Decimal-to-Octal Conversion

 0.
4375
0.4375 x 8 = 3.5
0.5 x8 = 4.0

0.437510 = 0.348

34
Decimal-to-Hexadecimal Conversion

 0 . 4375
0.4375 x =
16 7.0

0.437510 = 0.716

35
Example :Decimal-to-Binary Conversion(Estimation)

 0.78 110012  2-1 + 2-2 + 2-5


2 x 2 = 1.56  0.5 +
0.782
4 0.25 +0.03125
0.564 x 2 = 1.12  0.78125
8 110010000
0.128 x 2 = 0.25 12 2-1 + 2-2 + 2-5 + 2-10
6  0.5 + 0.25
0.256 x 2 = 0.51 +0.03125 +
2 0.0009765625
0.512 x 2 = 1.02  0.7822265625
4
0.024 x 2 = 0.04 36
Decimal to Octal Conversion

Example (Integer) : (175)10


Quotient Remainder Coefficient
175 / 8 = 21 7 a0 = 7
21 / 8 = 2 5 a1 = 5
2 /8= 0 2 a2 = 2
Answer: (175)10 = (a2 a1
a0)8 = (257)8

Example (Fractional) : (0.3125)10


Integer Fraction Coefficient
0.3125 * 8 =
0.5 *8 2 . 5 a-1 = 2
= 4 . 0 a-2 =
Answer: (0.3125)10 = (0.a-1 a-2 a-3)8 = (0.24)8
4 37
Practice Questions

• Convert the following from Decimals to Binary


» 259 , 245.50 , 89. 35
• Convert the following from Decimals to Octal
» 125 , 36.25 , 89. 45
• Convert the following from Binary to
Hexadecimal
» 101100.01010101 , 1011011.0101

38
Number Base Conversions : Practice Questions

• Convert the following from Decimal to


Binary Number System
– 25 , 30.25 , 19.125 , 36.333
• Convert the following from Decimal to Number
Octal System
– 59 , 77.50 , 89.140, 104.75
• Convert the following from Decimal to
Hexadecimal Number System
– 158 , 77.50 , 289.150

39
Exercise 2

 Convert these decimal


numbers to binary c) (22.5)10=(
system 2 22 ?)2
system numbers
a) 17 2 11 0
b) 38 2 5 1
c) 22.5
2 2 1
d) 764.375
1 0

0.5 x 2 = 1.0
=> (22.5)10=(
10110.1 )2 40
BaseX– to – BaseY 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

41
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

Assume Zeros Assume Zeros

( 0 1 0 1 1 0 . 0 1 0 )2

(1 6 . 4
)16
Works both ways (Octal to Hex & Hex to Octal)
44
Example

 Convert 372.348 to hexadecimal system


number
Convert 372.348 to decimal systemnumber
 372.348 = (3x82)+(7x81)+(2x80) .
(3x8-1) + (4x8-2)
= 192 + 56 + 2 .
0.375 + 0.0625
= 250 . 4375
Convert
250 / 16 =250.4375 0.4375system
10 to hexadecimal
15 remainder * 16 = 7.0
number 10 0.4375  0.716
250 10FA16
 250.4375
372.348 =
Positional number 45
Fractional number
Exercise 3 (TODO)

 Convert these numbers to octal


system number
11100.10012
1111112
5A.B16
 Convert these numbers to binary
system number
5A.B16
75.28

45
Number Base Conversion :Binary, Octal, Hexadecimal to Decimal

• For Base Conversion from Binary, Octal and


Hexadecimal to Decimal use the Sum*Weight
formula
2 1 0 -1
d -2
2 *B +d1*B +d0*B + d-1*B +d-2*B
Integer Part Fractional
Part
• Binary to Decimal Conversion
16

1 0 1 0 1
8
1 *24+0 *23+1 *22+0 *21+1 *20
4
=(21)10
2 46
Number Base Conversion
(Decimal to Binary, Octal, Hexadecimal)

• For Integer part


– Divide the number by the "Base"
– Take the remainder as a Coefficient
– Take the quotient and Repeat division
till quotient is ZERO or Less than
Base

• For Fractional part


– Multiply the number by Base
– Take integer part of result as coefficient
– Repeat the process with fractional part of
result till fraction is ZERO or desired accuracy
is achieved 47
Number Base Conversion – (Base R)

• For Integer part


– Divide the number by the "Base = R"
– Take the remainder as a Coefficient
– Take the quotient and Repeat division till
quotient is ZERO or Less than Base
• For Fractional part
– Multiply the number by "Base = R"
– Take integer part of result as coefficient
– Repeat the process with fractional part of result till
fraction is ZERO or desired accuracy is
achieved
• For conversion to decimal „Sum of WeightxDigit‟
48
Number Base Conversions : Practice Questions

• Convert the following from Decimal to Base =


4
– 15 , 25.45
• Convert the following from Decimal to Base =
7
– 17.50 , 29, 54.15
• Convert the following from Decimal to Base =
3
– 58 , 41.50
• Convert the following from Base = 6 to decimal
– (145)6 , (31.42) 6
49
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

50

You might also like