Week 4 Number Systems

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 84

SWE – 105T

INTRODUCTION TO COMPUTING
Software Engineering Department
Sir Syed University of Engineering & Technology

NUMBER SYSTEM AND


CONVERSIONS
1
Numbers
• Natural Numbers
Zero and any number obtained by repeatedly adding
one to it.
 
Examples: 100, 0, 45645, 32

• Negative Numbers
A value less than 0, with a – sign Examples: -24, -1, -
45645, -32
2
Numbers (Cont’d)
• Integers
A natural number, a negative number, zero
Examples: 249, 0, - 45645, - 32

• Rational Numbers
An integer or the quotient of two integers Examples:
-249, -1, 0, ¼ , - ½

3
Understanding Number System

• The radix, or base, of a number system is the total


number of unique symbols available in that
system.
• The largest valued symbol always has a magnitude
of one less than the radix.
• The study of binary system will help us gain better
understanding of how computers perform
computation.

4
Positional Notation

5
Types of Number System

There are various types of number system which as


follows:
 Decimal Number System
 Binary Number System
 Octal Number System
 Hexadecimal Number System

6
Types of Number System

•  Four most commonly used number systems are-

7
Number System

• The following table shows the base and digits


used in these number systems-
Number System Base Digits Used

Decimal Number 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
10
System (Total 10 digits)

Binary Number 0, 1
2
System (Total 2 digits)

Octal Number 8 0, 1, 2, 3, 4, 5, 6, 7
System (Total 8 digits)

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B,
Hexadecimal
16 C, D, E, F
Number System (Total 16 digits)

8
Conversion Among Bases

• The possibilities:

Decimal Octal

Binary Hexadecimal

9
Binary Number System

• Binary Number System


– It is the simplest form of number system. It consists of only two
digits in base which are 0 and 1 or on and off respectively
– They are used as the numbering system for computers. A binary
number can be easily represented by using a series of switches
– Each single digit in the binary system is called as a bit. When four
bits are combined together a nibble is formed
– Eight bits or two nibbles are combined to form a byte. Sixteen
bits or two bytes combine to form a word and similarly thirty two
bits or two words are called as a double word

10
Binary Number System

• The following is the diagrammatic representation of


binary number system:

11
Binary Numbers (cont.)
 Decimal Binary
 0 0000 8 + 2 = 10
1 0001
 2  0010
8 4 2 1
 3  0011
 4  0100 1010
 5  0101
 6  0110
Considering the digits that
 7  0111 has a value of 1 and adding
 8  1000 it number marker on the
top of each digits
 9  1001
 10  1010

12
Definitions
• nibble = 4 bits
• byte = 8 bits
• (short) word = 2 bytes = 16 bits
• (double) word = 4 bytes = 32 bits
• (long) word = 8 bytes = 64 bits
• 1K (kilo or “kibi”) = 1,024
• 1M (mega or “mebi”) = (1K)*(1K) = 1,048,576
• 1G (giga or “gibi”) = (1K)*(1M) = 1,073,741,824

13
Decimal Number System

Decimal system consists of 10 digits starting from 0


to 9. This number system has ten as its base.

14
Decimal Number System

• In number system,
• It is very important to have a good knowledge of
how to convert numbers from one base to
another base.
• Here, we will learn how to convert any given
number from any base to base 10.

15
Decimal Number System

• Converting to Base 10-


• A given number can be converted from any base
to base 10 using Expansion Method.
• According to expansion method, if abc.de is any
given number in base x, then its value in base 10
is given as-
(abc.de)x = (ax2 + bx + c + dx-1 + ex-2)10

16
Decimal Number System
• Explanation-

• To use expansion method for conversion,


• Assign position number to each digit of the given number.
• Digits to the left of decimal are numbered starting from 0.
• Digits to the right of decimal are numbered starting from -1.
• Write a term for each digit as digit x (base of given number) position
number of digit

• Perform the addition of all terms to obtain the number in base 10.
• This formula can be expanded for any number of digits.

17
Decimal Number System

18
Decimal to Binary Conversion( Base 10 to base
2)
• In number system,
• It is very important to have a good knowledge of
how to convert numbers from one base to
another base.
• Here, we will learn how to convert any given
number from base 10 to base 2.

19
Explanation

• Steps To Convert From Base 10 To Base 2-

• Multiply the given fraction (in base 10) with 2.


• Write the real part and fractional part of the result so obtained
separately.
• Multiply the fractional part with 2.
• Write the real part and fractional part of the result so obtained
separately.
• Repeat this procedure until the fractional part remains 0.
• If fractional part does not terminate to 0, find the result up to as
many places as required.
20
Decimal to Octal Conversion( Base 10 to Base 8)

• In number system,
• It is very important to have a good knowledge of
how to convert numbers from one base to
another base.
• Here, we will learn how to convert any given
number from base 10 to base 8.

21
Explanation
• Steps To Convert From Base 10 To Base 8
 
• Multiply the given fraction (in base 10) with 8.
• Write the real part and fractional part of the result so obtained
separately.
• Multiply the fractional part with 8.
• Write the real part and fractional part of the result so obtained
separately.
• Repeat this procedure until the fractional part remains 0.
• If fractional part does not terminate to 0, find the result up to as
many places as required.
22
Decimal to Hexadecimal Conversion( Base 10 to base 16)

• In number system,
• It is very important to have a good knowledge of
how to convert numbers from one base to
another base.
• Here, we will learn how to convert any given
number from base 10 to base 16.

23
Explanation

• Steps To Convert From Base 10 To Base 16

• Multiply the given fraction (in base 10) with 16.


• Write the real part and fractional part of the result so obtained
separately.
• Multiply the fractional part with 16.
• Write the real part and fractional part of the result so obtained
separately.
• Repeat this procedure until the fractional part remains 0.
• If fractional part does not terminate to 0, find the result up to as many
places as required.
 
24
Octal Number System

• Octal Number System


It is one of the most commonly used number system
in computers. It is used in programming because of
its similarity to binary number system
A single octal digit is equal to three binary digits.
Octal Number System uses the base as 8.
• Base 8
• Ten Digits: 0, 1, 2, 3, 4, 5, 6, 7
• Example: 238
25
Hexadecimal Number System

• Hexadecimal Number System


This number system is used for larger numbers.
Hexadecimal number system uses the base as 16
In hexadecimal number system the number 0 to 9
are denoted normally then the numbers 10 to 15
are denoted by alphabets A through F
respectively.

26
ASCII Code

• ASCII Code
– The American Standard Code for Information Interchange (ASCII) code is a
special form of BCD code that is widely used in digital computers and data
communications equipment.
– It is a 7-bit binary code that is used in transferring data between computers
and their external peripheral devices and in communicating data by radio
and telephone lines.
– The ASCII code is used to represent the 26 upper case letters (A to Z), 26
lowercase letters (a to z), 10 numbers (0 to 9), 33 special characters and
symbols and 33 control characters
– They are considered as a standard code for denoting character as binary
numbers which is used in computer terminals, printers and microcomputers
– If a file is saved in ASCII format it can be easily used by another application

27
Conversion of the Number System

• Binary to Decimal , Octal, Hexadecimal


• Decimal to Binary, Octal, Hexadecimal
• Octal to Decimal, Binary, Hexadecimal
• Hexadecimal to Binary, Octal, Decimal

28
Quick Example

2510 = 110012 = 318 = 1916

Base

29
Binary to Decimal
• Remember that Binary numbers are based on the radix of 2
while Decimal numbers are based on the radix of 10.

• Remember also that binary will only be represented in 1s and


0s.

• Steps in converting Binary to Decimal:


– Place a number marker on the top of the given digits, starting
from 0 up the last given digits—starting from the right to
determine the exponent to use.
– Consider all the 1s in the given digits and multiply it with the base
number of the given digits (which is base 2) and raised it with
power of the number corresponded in the number marker you
placed on the top of the given digits.
30
Example: Binary to Decimal
Place the number marker
on the top of the given
1010102 = ?10 digits, starting from the
right, starting from 0 up to
the last given digit on the
5 4 3 2 1 0
left.
= 101010

= 1*25 + 1*23 + 1*21

= 32 + 8 + 2

= 4210
31
Example: Binary to Decimal

• (10010)2 → ( ? )10

Using expansion method, we have-


(10010)2
= ( 1 x 24 + 0 x 23 + 0 x 22 + 1 x 21 + 0 x 20 )10
= ( 16 + 0 + 0 + 2 + 0 )10
= ( 18 )10
32
Example: Binary to Decimal

• (10010.101)2 → ( ? )10

Using expansion method, we have-


(10010.101)2
= ( 1 x 24 + 0 x 23 + 0 x 22 + 1 x 21 + 0 x 20 + 1 x 2-1 + 0 x 2-2 + 1 x
2-3 )10
= ( 16 + 0 + 0 + 2 + 0 + 0.5 + 0.125 )10
= ( 18.625 )10
 
33
Binary to Octal
• Since one octal digit is equivalent to three binary digits, just
group three binary digits, starting from the least significant
bit (right side).

• Append 0 to the most significant bit (left side), if the grouping


does not have enough to form three binary digits.

• In short, you must complete the grouping of three digits.

• If you will be having a fraction (decimal point), append 0 to


the least most significant bit (right side) of the given digits to
complete the grouping of three bits.

34
Binary to Octal (cont.)
• Steps in converting Binary to Octal:
– Group the given digits in three starting from the
right side.
– If the grouping is not complete, place 0 to
complete the grouping.
– Once you have grouped it into three digits, you
starting converting the binary digits into decimal
values following the concepts of binary digits (4, 2,
1) starting from the right.

35
Binary to Octal Conversion

36
Example: Binary to Octal

(1101010)2 = ?8
3rd group 2nd group 1st group

= 001 101 010


Add 0 to the left, to
complete the
grouping 4 2 1 4 2 1 4 2 1

= 001 101 010


Simply add all the
number markers
= 1 5 28 considering the
binary digits that has
1 on it.
= 1528
37
Example: Binary to Octal

(1010)2=( ? )8

Split the binary number from left to right each group 3 bits
001 010
1 2

(1010)2=(12)8

38
Example: Binary to Octal

(111110011001)2= ?8

Split the binary number from left to right each


group 3 bits
111 110 011 001
7 6 3 1

(111110011001)2=(7631)8
39
Binary to Hexadecimal
• Since one hexadecimal digit is equivalent to four binary digits,
just group four binary digits, starting from the least significant
bit (right side).

• Append 0 to the most significant bit (left side), if the grouping


does not have enough to form four binary digits.

• In short, you must complete the grouping of four digits.

• If you will be having a fraction (decimal point), append 0 to


the least most significant bit (right side) of the given digits to
complete the grouping of three bits.

40
Binary to Hexadecimal (cont.)

• Steps in converting Binary to Hexadecimal:


– Group the given digits in four starting from the right
side.
– If the grouping is not complete, place 0 to complete
the grouping.
– Once you have grouped it into three digits, you
starting converting the binary digits into decimal
values following the concepts of binary digits (8, 4, 2,
1) starting from the right.

41
Binary to Hexa conversions

42
Example: Binary to Hexadecimal
Simply add all the
(1101010)2 = ?16 number markers
considering the
2nd group 1st group binary digits that has
1 on it.
= 0110 1010
Add 0 to the left, to
complete the
8 4 2 1 8 4 2 1
grouping
= 0110 1010

= 6 A16

= 6A16
43
Example: Binary to Hexadecimal
10101110112 = ?16

10 1011 1011

2 B B

10101110112 = 2BB16
44
Decimal to Binary

• Converting a decimal number to a binary number


is done by successively dividing the decimal
number by 2 on the left side of the radix.
• If you will have a fractional part of the given
decimal, successively multiplying the decimal
number by 2 on the right side of the radix.

45
Decimal to Binary (cont.)

• Steps in converting Decimal to Binary:


– Divide the given decimal number with the base
number you are converting it to, which is 2.
– Whatever the answer you will get in the division will
be divided again with the base (2) until you cannot
divide the answer anymore with 2.
– The remainder that you will get will be the one you
consider as your converted answer.

46
Example: Decimal to Binary
(125)10 = ?2 2 125
2 62 1
2 31 0
2 15 1
2 7 1
2 3 1
2 1 1
0 1

12510 = 11111012

47
Example: Decimal to Binary

• (18)10 → ( ? )2
• Using division method, we have-

• From here, (18)10 = (10010)2


48
Example: Decimal to Binary

• (172)10 → ( ? )2
• Using division method, we have-

• From here, (172)10 = (10101100)2

49
Decimal to Octal

• Converting a decimal number to an octal number


is done by successively dividing the decimal
number by 8 on the left side of the radix.
• If you will have a fractional part of the given
decimal, successively multiplying the decimal
number by 8 on the right side of the radix.

50
Decimal to Octal (cont.)

• Steps in converting Decimal to Octal:


– Divide the given decimal number with the base
number you are converting it to, which is 8.
– Whatever the answer you will get in the division will
be divided again with the base (8) until you cannot
divide the answer anymore with 8.
– The remainder that you will get will be the one you
consider as your converted answer.

51
Example: Decimal to Octal
123410 = ?8

8 1234
8 154 2
8 19 2
8 2 3
0 2

123410 = 23228

52
Example: Decimal to Octal

10 
• (1032) → (?)
8

• Using division method, we have-

• From here, (1032)10 = (2010)8

53
Example: Decimal to Octal

• (172)10 → ( ? )8
• Using division method, we have-

• From here, (172)10 = (254)8


 
54
Decimal to Hexadecimal

• Converting a decimal number to a hexadecimal


number is done by successively dividing the
decimal number by 16 on the left side of the radix
• If you will have a fractional part of the given
decimal, successively multiplying the decimal
number by 16 on the right side of the radix.

55
Decimal to Hexadecimal (cont.)

• Steps in converting Decimal to Hexadecimal:


– Divide the given decimal number with the base number you are
converting it to, which is 16.
– Whatever the answer you will get in the division will be divided
again with the base (16) until you cannot divide the answer
anymore with 16.
– The remainder that you will get will be the one you consider as
your converted answer.

56
Example: Decimal to Hexadecimal
123410 = ?16

16 1234
16 77 2
16 4 13 = D
0 4

123410 = 4D216

57
Example: Decimal to Hexadecimal

• (2020)10 → (?)16
• Using division method, we have-

• From here, (2020)10 = (7E4)16

58
Example: Decimal to Hexadecimal

• (172)10 → ( ? )16
• Using division method, we have-

• From here, (172)10 = (AC)16

59
Octal to Decimal
• Remember that Octal numbers are based on the radix of 8 while Decimal
numbers are based on the radix of 10.
• Remember also that Octal will only be represented with value 0-7.
• Steps in converting Octal to Decimal:
– Place a number marker on the top of the given digits, starting from 0 up the
last given digits—starting from the right to determine the exponent to use.
– Considering all the given digits, multiply it with the base number of the
given digits (which is base 8) and raised it with power of the number
corresponded in the number marker you placed on the top of the given
digits.

60
Example: Octal to Decimal
Place the number marker
on the top of the given
(761)8 = ?10 digits, starting from the
right, starting from 0 up to
the last given digit on the
2 1 0
left.
= 761

= 7*82 + 6*81 + 1*80

= 56 + 48 + 1

= 10510
61
Example: Octal to Decimal

(254)8 → ( ? )10
Using expansion method, we have-
(254)8
= ( 2 x 82 + 5 x 81 + 4 x 80 )10

= ( 128 + 40 + 4 )10

= ( 172 )10
62
Example: Octal to Decimal

(254.7014)8 → ( ? )10
Using expansion method, we have-
(254.7014)8
= ( 2 x 82 + 5 x 81 + 4 x 80 + 7 x 8-1 + 0 x 8-2 + 1 x 8-3 + 4 x 8-4 )10

= ( 128 + 40 + 4 + 0.875 + 0.0019 + 0.0009 )10

= ( 172.8778 )10
63
Binary to Octal Conversion

64
Octal to Binary

• Since one octal digit is equivalent to three binary


digits, just convert the individual octal digit into
three binary digits.
• Steps in converting Octal to Binary:
– Convert each of the given octal number by simply
using the concept of (4, 2, 1).
– Place a binary 1 to correspond the given octal
number.

65
Example: Octal to Binary
Simply add all the number
(761)8 = ?2 markers considering the
binary digits that has 1 on
it, to get the octal number
4 2 1
given.
= 7 111
4 2 1

= 6 110
4 2 1

= 1 001

= 111 110 0012


66
Example: Octal to Binary
7058 = ?2

7 0 5

111 000 101

7058 = 1110001012

67
Octal to Hexadecimal

• When converting an octal digit to a hexadecimal digit, you


must first convert the octal number to binary number and
group it by four and convert the grouped digits to
hexadecimal by using the concept of (8, 4, 2, 1).
• If the digits is not enough to form a grouping of four then
append 0 on the left side of the digits.
• If the given octal have fraction, then append 0 on the right
side of the given digits.

68
Octal to Hexadecimal (cont.)

• Steps in converting Octal to Hexadecimal:


– Convert the octal digits in binary by considering each
given digits and represent it in binary using the
concept (4, 2, 1).
– Once it is in binary, that’s the time you convert the
binary into hexadecimal, by grouping it into four.

69
Example: Octal to Hexadecimal

(761)8 = ?16

= 111 110 0017 6 1

= 0001 1111 0001


1 F 1

= 1F116

70
Example: Octal to Hexadecimal
10768 = ?16
1 0 7 6

001 000 111 110

2 3 E

10768 = 23E16
71
Hexadecimal to Binary

• Since one hexadecimal digit is equivalent to four


binary digits, just convert the individual
hexadecimal digit into four binary digit

72
Example: Hexadecimal to Binary

(7AE3)16 = ?2

= 7 0111
A 1010
E 1110
3 0011

= (0111 1010 1110 0011)2


73
Example: Hexadecimal to Binary
10AF16 = ?2

1 0 A F

0001 0000 1010 1111

10AF16 = 00010000101011112

74
Hexadecimal to Octal

• When converting an hexadecimal digit to an octal digit, you


must first convert the hexadecimal number to binary number
and group it by three and convert the grouped digits to octal
by using the concept of (4, 2, 1).
• If the digits is not enough to form a grouping of three then
append 0 on the left side of the digits.
• If the given hexadecimal have fraction, then append 0 on the
right side of the given digits.

75
Hexadecimal to Octal (cont.)

• Steps in converting Hexadecimal to Octal:


– Convert the hexadecimal digits in binary by
considering each given digits
– Once converted to binary group the binary into three
and using the concept (4, 2, 1).

76
Example: Hexadecimal to Octal

7AE316 = ?8

= 7 0111
A 1010
E 1110
3 0011

= 0 111 101 011 100


7 011
5 2 3 4 3

= 753438
77
Example: Hexadecimal to Octal
1F0C16 = ?8

1 F 0 C

0001 1111 0000 1100

1 7 4 1 4

1F0C16 = 174148
78
Hexadecimal to Decimal
• Each hexadecimal position is weighted with a power of 16.
• Digits on the left side of the radix point has a positive
exponent while on the right side of the radix point has a
negative exponent.
• Converting a hexadecimal number to a decimal number is
done by successively multiplying the decimal number by 16
on the left side of the radix
• If you will have a fractional part of the given decimal,
successively multiplying the decimal number by 16 on the
right side of the radix.

79
Hexadecimal to Decimal (cont.)

• Steps in converting Hexadecimal to Decimal:


– Place a number marker on the top of the given
number for determining the exponent to be used.
– Get the individual digit and multiply it by the base
number (16) and raised it with the exponent
corresponds to the number marker you place on each
digit, then to the addition operation.

80
Example: Hexadecimal to Decimal

286A16 = ?10
3 2 1 0

= 286A

= 2*163 + 8*162 + 6*161 + A*160

= 1034610

81
Example: Hexadecimal to Decimal

(AC)16 → ( ? )10
 Using expansion method, we have-
(AC)16
= ( A x 161 + C x 160 )10
= ( 10 x 16 + 12 x 1 )10
= ( 160 + 12 )10
= ( 172 )10

82
Example: Hexadecimal to Decimal
(AC.FBA5)16 → ( ? )10
 
Using expansion method, we have-
(AC.FBA5)16
= ( A x 161 + C x 160 + F x 16-1 + B x 16-2 + A x 16-3 + 5 x 16-4 )10

= ( 10 x 16 + 12 x 1 + 15 x 16-1 + 11 x 16-2 + 10 x 16-3 + 5 x 16-4 )10

= ( 160 + 12 + 0.9375 + 0.0429 + 0.0024 + 0.0001 ) 10

= ( 172.9829 )10

83
Conversion Table

84

You might also like