0% found this document useful (0 votes)
7 views

Lecture 5 - Number System Conversions

Uploaded by

abiarunja72
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Lecture 5 - Number System Conversions

Uploaded by

abiarunja72
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 45

SLIIT City Uni

Higher Diploma in
Information Technology –
Year 01, Semester 01

Computing Fundamentals

Number System conversions


Lecture 05
SLIIT City Uni (Pvt) Ltd. © 2024
Outline
 Number systems
 Conversion of Integers
 Conversion of fractions

SLIIT City Uni (Pvt) Ltd. © 2024


Decimal Number System
 The number system that we use in our day-to-
day life is called the Decimal number system.
 In this system, the base is equal to ten (10).
 Means that we use only digits:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9 to write any
number.
 The successive positions to the left of the
decimal point represent
units, tens, hundreds, thousands, and etc.
SLIIT City Uni (Pvt) Ltd. © 2024
Example
 The decimal number 2586 (written as 258610)
 Consists of the digit :
 6 in the units position,
 8 in the tens position,
 5 in the hundreds position, and
 2 in the thousands position and its value can be written
as:
(2 x 1000) + (5 x 100) + (8 x 10) + (6 x 1) or
2000 + 500 + 80 + 6 or
2586
SLIIT City Uni (Pvt) Ltd. © 2024
Binary Number System
 The number system that has only two symbols, then its base is 2
is called the Binary Number System.
 The two symbols used in the system:
0 and 1 are binary digits or bits.
 The successive positions to the left of the decimal point
represent
units, twos, fours, eights, and etc.
 Like before the following binary number means.
1 0 1 12

1x23 0x22 1x21 1x20


SLIIT City Uni (Pvt) Ltd. © 2024
Octal & Hexadecimal Number
Systems
 These two number bases can be used to
represent binary numbers in a short form
notation.
 Because…
 Octal – uses Base 8 and
 Hexadecimal – Base 16 is a convenient notation to
express binary numbers.

SLIIT City Uni (Pvt) Ltd. © 2024


Octal Number System
 In the octal number system the base is 8.
 So…in this system there are only eight (8)
symbols or digits:
01234567
 Like before the following octal number means.
27208

2x83 + 7x82 + 2x81 + 0x80


SLIIT City Uni (Pvt) Ltd. © 2024
Hexadecimal Number System
 The hexadecimal number system is one with a base
of 16.
 The base 16 suggests choices of 16 single character
digits or symbols.
 The first 10 digits are the digits of a decimal system:
A – 10
0123456789
B – 11
 The remaining six digits are denoted by:
C – 12
ABCDEF D – 13
 Representing the decimal values: E – 14
SLIIT City Uni (Pvt) Ltd. © 2024 F – 15
CONVERSION OF
INTEGERS
SLIIT City Uni (Pvt) Ltd. © 2024
Decimal to Binary
 To convert a decimal integer to binary,
 divide the number successively by 2, and
 after each division record the remainder
 which is either 1 or 0.
 Continue the division until the answer becomes 0

SLIIT City Uni (Pvt) Ltd. © 2024


Example
155 → ? Remainder
 The result is read
155/2 → 1 from the
77/2 → 1  Most significant
38/2 → 0 bit…
Collect
19/2 → 1  The last
9/2 → 1 remainder
4/2 → 0 upwards to give;
2/2 → 0
1/2 → 1
15510 = 100110112
0
SLIIT City Uni (Pvt) Ltd. © 2024
Exercises 01
 Convert the following decimal numbers to binary
 68
 135

SLIIT City Uni (Pvt) Ltd. © 2024


Decimal to Octal
 The process is as above accepting that division is by 8. In
this case remainder is a number in the range 0 to 7.

2371 → ?

2371/8 →3
296/8 →0 237110 = 45038
Collect
37/8 → 5
4/8 →4
0
SLIIT City Uni (Pvt) Ltd. © 2024
Decimal to Hexadecimal
 Decimal numbers are converted from decimal into
hexadecimal form in exactly the same way as the above.
 However, in this case the remainder lies in the decimal
range 0 to 15, corresponding to the hexadecimal range
0 to F.
Example : 946 → ?
946/16 → 2
94610 = 3B216
59/16 → 11 (B) Collect

3/16 → 3
0
SLIIT City Uni (Pvt) Ltd. © 2024
Exercise
 Convert the following numbers into binary, octal
and hexadecimal
Binary Octal Hexa

 68 1000100 104 44
 135 10000111 207 87

 734 1011011110 1336 2DE

SLIIT City Uni (Pvt) Ltd. © 2024


Binary to Decimal
 Method 1: Expansion method
 Expand the definition by multiplying each binary
digit with its positional value. Add the multiplied
values together
100110112
= 1x27 + 0x26 + 0x25 + 1x24 + 1x23 + 0x22 + 1x21 + 1x20
= 1x128 + 0x64 + 0x32 + 1x16 + 1x8 + 0x4 + 1x2 + 1x1
= 155

SLIIT City Uni (Pvt) Ltd. © 2024


Binary to Decimal
 Method 2:
 It is possible to convert a binary number to decimal by
adding together the requisite power of two.
 A more methodical technique is based on a recursive
algorithm as follows.
 Take the left most none zero bit,
 double it and
 add it to the bit on its right.
 Now take this result,
 double it and
 add it to the next bit on the right.
 Continue in this way until the least significant bit has been
SLIIT City Uni (Pvt) Ltd. © 2024
added in.
Binary to Decimal Method 2

10101112 = 8710

SLIIT City Uni (Pvt) Ltd. © 2024


Binary to Octal
 Form the bits into groups of three starting at the binary
point and moving leftwards.
 Replace each group of three bits with the corresponding
octal digit (0 to 7).
 As 8 is a power of 2, namely 23, there is one-to-one
correspondence between octal digit and its binary
equivalent.
 That’s the reason…
 Need only 3 bits to represent a octal digit.
 Note how the binary number has been condensed to a
more manageable size.
SLIIT City Uni (Pvt) Ltd. © 2024
Binary to Octal
Decimal Binary Octal
0 000 0 10110111
1 001 1
2 010 2
3 011 3 10110111
4 100 4
5 101 5
6 110 6
7 111 7 2 6 7

 101101112 = 2678

SLIIT City Uni (Pvt) Ltd. © 2024


Binary to Hexadecimal
 The binary number is formed into groups of four
bits starting at the decimal point.
 Each group is replaced by a hexadecimal digit
from 0 to 9, A, B, C, D, E, and F.
 As 16 is a power of 2, namely 24, there is one-to-
one correspondence between hexadecimal digit
and its binary equivalent.
 That’s the reason…
 Need only 4 bits to represent a hexadecimal digit
SLIIT City Uni (Pvt) Ltd. © 2024
Binary to Hexadecimal
Decimal Binary Hex
• 0 0000 0
• 1 0001 1 1110110111
• 2 0010 2
• 3 0011 3
• 4 0100 4
• 5 0101 5
• 6 0110 6 1110110111
• 7 0111 7
• 8 1000 8
• 9 1001 9
• 10 1010 A
• 11 1011 B 3 B 7
• 12 1100 C
 1110110111 = 3B716
• 13 1101 D 2

• 14 1110 E
• 15 1111 F
SLIIT City Uni (Pvt) Ltd. © 2024
Octal to Decimal
 Method 1: Expansion method
 Expand the definition by multiplying each Octal digit with its
positional value. Add the multiplied values together
45038
83 82 81 80
(512) (64) (8) (1)
4 5 0 3
= 4x512 + 5x64 + 0x8 + 3x1
= 2371

 45038 = 237110
SLIIT City Uni (Pvt) Ltd. © 2024
Octal to Decimal
 Method 2:
 We take the left-most digit,
 Multiply it by eight and
 Add it to the digit on its right.
 Then multiply this subtotal by eight and add it
to the next digit on its right.
 The process ends when the left-most digit has
been added to the subtotal.
SLIIT City Uni (Pvt) Ltd. © 2024
Octal to Decimal : Method 2

64378 = 335910

SLIIT City Uni (Pvt) Ltd. © 2024


Octal to Binary
 Converting an octal number into its binary equivalent
requires the reverse procedure of converting from binary
to octal.
 Each octal digit is simply replaced by its 3-bit binary
equivalent.
 It is important to remember that (say) 3 must be replaced
by 011 and not 11.

SLIIT City Uni (Pvt) Ltd. © 2024


Octal to Binary
Decimal Binary Octal
0 000
0 1 5 68
1 001
1
2 010 001 101 110
2
3 011 01101110
3
4 100 4  1568 = 011011102
5 101 5
6 110 SLIIT City Uni (Pvt) Ltd. © 2024
Hexadecimal to Decimal

 Method 1: Expansion 3B216


method
163 162 161 160
 Expand the definition by
(4096) (256) (16) (1)
multiplying each
Hexadecimal digit with its
= 3x256 + 11x16 + 2x1
positional value. Add the
= 946
multiplied values
together
 3B216 = 94610

SLIIT City Uni (Pvt) Ltd. © 2024


Hexadecimal to Decimal

 Method 2:
 The method is identical
to the procedures for
binary and octal except
that 16 is used as a
multiplier.

1AC16 = 42810

SLIIT City Uni (Pvt) Ltd. © 2024


Hexadecimal to Binary
Decimal Binary Each hexadecimal digit is replaced by its 4-bit binary
Hex equivalent.
• 0 0000 0
• 1 0001 1
• 2 0010 2


3
4
0011
0100
3
4
7 0 C
• 5 0101 5
• 6 0110 6
• 7 0111 7
• 8 1000 8 11100001100
• 9 1001 9
• 10 1010 A
• 11 1011 B
• 12 1100 C
• 13 1101 D  70C16= 111000011002
• 14 1110 E
• 15 1111 F SLIIT City Uni (Pvt) Ltd. © 2024
Exercises
 Convert the following numbers
 100101112 to Decimal, Octal and Hexadecimal
 37028 to Decimal, Binary
 10DF16 to Decimal and Binary

SLIIT City Uni (Pvt) Ltd. © 2024


Exercises Answers
 Convert the following numbers
 100101112 = 151
= 2278
= 9716
 37028 = 1986
= 0111110000102
 10DF16 = 4319
= 00010000110111112
SLIIT City Uni (Pvt) Ltd. © 2024
CONVERTING
FRACTIONS
SLIIT City Uni (Pvt) Ltd. © 2024
Conversion of Fractions
 The conversion of fraction from one base to
another is carried out in a similar way to the
conversion of integer,
 although it is rather more tedious to manipulate
fractions manually.

SLIIT City Uni (Pvt) Ltd. © 2024


Decimal Fraction
 Fractions can be expanded in the same way.
 Examples:

245.75

102 101 100 10-1 10-2


2x102 + 4x101 + 5x100 + 7x10-1 +
5x10-2

SLIIT City Uni (Pvt) Ltd. © 2024


Binary Fractions
 Binary Fractions can be extended the same way.

11.1012

21 20 2-1 2-2 2-3


2 1 0.5 0.25 0.125

SLIIT City Uni (Pvt) Ltd. © 2024


Binary Fraction to Decimal – Method
1
 Just expand the definition

110.10112

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


4 2 1 0.5 0.25 0.125 0.0625

1x4 + 1x2 + 0x1 + 1x0.5 + 0x0.25 + 1x 0.125 +


1x0.0625
 110.10112= 6.687510

SLIIT City Uni (Pvt) Ltd. © 2024


Binary Fraction to Decimal – Method
2
 The algorithm for converting binary fractions to
their decimal equivalent is based on the fact that a
bit in one column is worth half the value of a bit in
the column on its left.

 Starting at the right most non-zero bit,


 Take that bit and halve it.
 Now add the result to the next bit on its left.
 Halve this result and add it to the next bit on the left.
 Continue until the binary point is reached.
SLIIT City Uni (Pvt) Ltd. © 2024
Binary Fraction to Decimal – Method
2 Example

0.011012 = 13/32 or 0.40625

SLIIT City Uni (Pvt) Ltd. © 2024


Decimal Fraction to Binary
 Two multiplies the decimal fraction and the integer
part noted.
 The integer, which will be either 1 or 0, is then
stripped from the number to leave a fractional part.
 The new fraction is multiplied by two and the integer
part noted.
 We continue in this way until the process ends or a
sufficient degree of precision has been achieved.
 The binary fraction is formed by reading the integer
parts from the top to the bottom.
SLIIT City Uni (Pvt) Ltd. © 2024
Decimal Fraction to Binary – Example

0.8125 → ?
0.8125 x 2 = 1.625 → 1
0.625 x 2 = 1.25 → 1 0.1101
0.25 x 2 = 0.5 → 0
0.5 x 2 = 1.0 → 1
0 Collect
 0.812510= 0.11012

SLIIT City Uni (Pvt) Ltd. © 2024


Consider the following example

0.7 → ?
0.7 x 2 = 1.4 → 1
0.4 x 2 = 0.8 → 0
0.8 x 2 = 1.6 → 1 0.1011001100110...
0.6 x 2 = 1.2 → 1
0.2 x 2 = 0.4 → 0
0.4 x 2 = 0.8
… SLIIT City Uni (Pvt) Ltd. © 2024
Converting between Octal / Hexadecimal
Fractions Decimal Fractions
 We can convert between octal or hexadecimal
fractions and decimal.
 We have to change is the base (i.e. 2 to 8 or 2 to
16).

SLIIT City Uni (Pvt) Ltd. © 2024


Exercises
 Convert the following fractions
 0.658 to binary, octal and hexadecimal
 0.111012 to decimal, octal and hexadecimal
 0.458 to decimal and binary
 0.E216 to decimal and binary

SLIIT City Uni (Pvt) Ltd. © 2024


Exercises
 Convert the following fractions
 0.658 = 0.1010100…
= 0.520712…
= 0.A872…
 0.111012 = 0.90625
 0.458 = 0.578125
0.1001012
 0.E216 = 0.8828125
0.1110001016
SLIIT City Uni (Pvt) Ltd. © 2024

You might also like