0% found this document useful (0 votes)
114 views38 pages

Course Title: Computer Programming Language: Department of Naval Architecture & Marine Engineering

This document discusses number systems used in computer programming. It describes non-positional and positional number systems, focusing on decimal, binary, octal, and hexadecimal positional number systems. Methods for converting between different number bases are provided, including dividing and using remainders to change between decimal, binary, octal, and hexadecimal representations of numbers. Shortcut methods are also described, such as grouping binary digits in threes to directly obtain the octal equivalent.
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)
114 views38 pages

Course Title: Computer Programming Language: Department of Naval Architecture & Marine Engineering

This document discusses number systems used in computer programming. It describes non-positional and positional number systems, focusing on decimal, binary, octal, and hexadecimal positional number systems. Methods for converting between different number bases are provided, including dividing and using remainders to change between decimal, binary, octal, and hexadecimal representations of numbers. Shortcut methods are also described, such as grouping binary digits in threes to directly obtain the octal equivalent.
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/ 38

Department of Naval Architecture & Marine Engineering

Course Title:
Computer Programming
Language
Tarannum Zaki
Lecturer
Dept. of CSE, MIST

1
Number Systems

• Number systems are the technique to represent numbers in the computer


system architecture, every value that you are saving or getting into/from
computer memory has a defined number system.

• Two types of number systems –

– Non-Positional number system

– Positional number system

2
Non-Positional Number Systems

 Characteristics
 Use symbols such as I for 1, II for 2, III for 3, IIII for 4, IIIII for 5,
etc.
 Each symbol represents the same value regardless of its position in
the number
 The symbols are simply added to find out the value of a particular
number
 It is difficult to perform arithmetic with such a number system

3
Positional Number Systems

 Characteristics

 Use only a few symbols called digits


 These symbols represent different values depending on the position
they occupy in the number
 It is easy to perform arithmetic with such a number system
 Decimal, Hexadecimal, Octal, Binary Number System

4
Positional Number Systems

 The value of each digit is determined by:


1. The digit itself
2. The position of the digit in the number
3. The base of the number system

(base = total number of digits in the number system)


 The maximum value of a single digit is always equal to one less than
the value of the base

5
Decimal Number Systems

Characteristics
 A positional number system
 Has 10 symbols or digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9). Hence, its
base = 10
 The maximum value of a single digit is 9 (one less than the value
of the base)
 Each position of a digit represents a specific power of
the base (10)
 We use this number system in our day-to-day life

6
Decimal Number Systems

Example

258610 = (2 x 103) + (5 x 102) + (8 x 101) + (6 x 100)

= 2000 + 500 + 80 + 6

7
Binary Number Systems

Characteristics

 A positional number system

 Has only 2 symbols or digits (0 and 1). Hence, its base = 2

 Each position of a digit represents a specific power of the base (2)


 The maximum value of a single digit is 1 (one less than the value of the
base)

 This number system is used in computers

8
Binary Number Systems

Example
101012 = (1 x 24) + (0 x 23) + (1 x 22) + (0 x 21) x (1 x 20)

= 16 + 0 + 4 + 0 + 1
= 2110

9
Representing Numbers in Different Number Systems

In order to be specific about which number system we are


referring to, it is a common practice to indicate the base as a
subscript. Thus, we write:

101012 = 2110

10
Bit

 Bit stands for binary digit

 A bit in computer terminology means either a 0 or a 1

 A binary number consisting of n bits is called an n-bit number

11
Octal Number System

Characteristics
 A positional number system
 Has total 8 symbols or digits (0, 1, 2, 3, 4, 5, 6, 7).
Hence, its base = 8
 The maximum value of a single digit is 7 (one less
than the value of the base
 Each position of a digit represents a specific power of the
base (8)

12
Octal Number System

 Since there are only 8 digits,3 bits (23 = 8) are


sufficient to represent any octal number in binary

Example
20578 = (2 x 83) + (0 x 82) + (5 x 81) + (7 x 80)

= 1024 + 0 + 40 + 7
= 107110

13
Hexadecimal Number System

Characteristics
 A positional number system
 Has total 16 symbols or digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
A, B, C, D, E, F). Hence its base = 16
 The symbols A, B, C, D, E and F represent the
decimal values 10, 11, 12, 13, 14 and 15
respectively
 The maximum value of a single digit is 15 (one less than
the value of the base)

14
Hexadecimal Number System

 Each position of a digit represents a specific power of the


base (16)
 Since there are only 16 digits, 4 bits (24 = 16) are sufficient
to represent any hexadecimal number in binary

Example
1AF16 = (1 x 162) + (A x 161) + (F x 160)
= 1 x 256 + 10 x 16 + 15 x 1
= 256 + 160 + 15
= 43110
15
Converting a Number of Another Base to a Decimal Number

Method
Step 1: Determine the column (positional) value of each
digit
Step 2: Multiply the obtained column values by the digits
in the corresponding columns
Step 3: Calculate the sum of these products

16
Converting a Number of Another Base to a Decimal Number

Example
47068 = ?10
Common

47068 = 4 x 83 + 7 x 82 + 0 x 81 + 6 x 80
values corresponding
= 4 x 512 + 7 x 64 + 0 + 6 x 1 digits
multiplied
= 2048 + 448 + 0 + 6 by the
Sum of these
products
= 250210

17
Converting a Decimal Number to a Number of Another Base

Division-Remainder Method
Step 1: Divide the decimal number to be converted by
the value of the new base

Step 2: Record the remainder from Step 1 as the


rightmost digit (least significant digit) of
the new base number

Step 3: Divide the quotient of the previous divide by the


new base

18
Converting a Decimal Number to a Number of Another Base

Step 4: Record the remainder from Step 3 as the next


digit (to the left) of the new base number

Repeat Steps 3 and 4, recording remainders from right to


left, until the quotient becomes zero in Step 3

Note that the last remainder thus obtained will be the most
significant digit (MSD) of the new base number

19
Converting a Decimal Number to a Number of Another Base

Example
95210 = ?8

Solution:
8
119 s 0
952
14
Remainder 7
1 6
0 1

Hence, 95210 = 16708


20
Converting a Number of Some Base to a Number of Another
Base

Method

Step 1: Convert the original number to


a decimal number (base 10)

Step 2: Convert the decimal number so obtained to


the new base number

21
Converting a Number of Some Base to a Number of Another
Base

Example
5456 = ?4

Solution:
Step 1: Convert from base 6 to base 10

5456 = 5 x 62 + 4 x 61 + 5 x 60
= 5 x 36 + 4 x 6 +
5x1
= 180 + 24 + 5
= 20910

22
Converting a Number of Some Base to a Number of Another
Base

Step 2: Convert 20910 to base 4

4 209 Remainders
52 1
13 0
3 1
0 3

Hence, 20910 = 31014

So, 5456 = 20910 = 31014

Thus, 5456 = 31014


23
Shortcut Method for Converting a Binary Number to its
Equivalent Octal Number

Method
Step 1: Divide the digits into groups of three starting
from the right

Step 2: Convert each group of three binary digits to one


octal digit using the method of binary to decimal
conversion

24
Shortcut Method for Converting a Binary Number to its
Equivalent Octal Number

Example
11010102 = ?8

Step 1: Divide the binary digits into groups of 3


starting from right

001 101 010

Step 2: Convert each group into one octal digit

0012 = 0 x 22 + 0 x 21 + 1 x 20 = 1
1012 = 1 x 22 + 0 x 21 + 1 x 20 = 5
0102 = 0 x 22 + 1 x 21 + 0 x 20 = 2

Hence, 11010102 = 1528


25
Shortcut Method for Converting an Octal Number to its
Equivalent Binary Number

Method
Step Convert each octal digit to a 3 digit binary
number (the octal digits may be treated as
1: decimal for this conversion)
Step 2: Combine all the resulting binary groups
(of 3 each) into single binary
digits a
number

26
Shortcut Method for Converting an Octal Number to its
Equivalent Binary Number

Example
5628 = ?2

Step 1: Convert each octal digit to 3 binary


digits 58 = 1012, 68 = 1102, 28 =
0102

Step 2: Combine the binary


groups 5628 = 101 110
010
5

6
27
2
Shortcut Method for Converting a Binary Number to its
Equivalent Hexadecimal Number

Method

Step 1: Divide the binary digits into groups of four


starting from the right

Step 2: Combine each group of four binary digits


to one hexadecimal digit

28
Shortcut Method for Converting a Binary Number to its
Equivalent Hexadecimal Number
Example

1111012 = ?16

Step 1: Divide the binary digits into groups of four


starting from the right

0011 1101

Step 2: Convert each group into a hexadecimal digit


00112 = 0 x 23 + 0 x 22 + 1 x 21 + 1 x 20 =
310 = 316
11012 = 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20 =
310 = D16

29
Hence, 1111012 = 3D16
Shortcut Method for Converting a Hexadecimal Number to its
Equivalent Binary Number

Method

Step 1: Convert the decimal equivalent of each


hexadecimal digit to a 4 digit binary
number

Step 2: Combine all the resulting binary groups


(of 4 digits each) in a single binary number

30
Shortcut Method for Converting a Hexadecimal Number to its
Equivalent Binary Number
Example

2AB16 = ?2

Step 1: Convert each hexadecimal digit to a 4


digit binary number

= 00102
216 = 210
A16 = 1010 = 10102
B16 = 1110 = 10112

31
Shortcut Method for Converting a Hexadecimal Number to its
Equivalent Binary Number

Step 2: Combine the binary groups


2AB16 = 0010 1010 1011
2 A B

Hence, 2AB16 = 0010101010112

32
Fractional Numbers

Fractional numbers are formed same way as


decimal number system
In general, a number in a number system with base
b
would be written as:
an an-1… a0 . a-1 a-2 … a-m

And would be interpreted to mean:


an x bn + an-1 x bn-1 + … + a0 x b0 + a-1 x b-1 + a-2 x b-2 +

The+ asymbols
-m x b
-m
an, …, in above representation
an-1, a-m
should be one of the b symbols allowed in the
number system

33
Formation of Fractional Numbers in Binary Number
System (Example)

Binary Point

Position 4 3 2 1 0 . -1 -2 -3 -4

Position Value 24 23 22 21 20 2-1 2-2 2-3 2-4

Quantity 16 8 4 2 1 1/ 1/ 1/ 1/
2 4 8 16
Represented

34
Formation of Fractional Numbers in Binary Number
System (Example)

Example

110.1012 = 1 x 22 + 1 x 21 + 0 x 20 + 1 x 2-1 + 0 x 2-2 + 1 x 2-3

= 4 + 2 + 0 + 0.5 + 0 + 0.125

= 6.62510

35
Formation of Fractional Numbers in Octal Number
System (Example)

Octal Point

Position 3 2 1 0 . -1 -2 -3

Position Value 83 82 81 80 8-1 8-2 8-3

Quantity 512 64 8 1 1/ 1/ 1/
8 64 512
Represented

36
Formation of Fractional Numbers in Octal Number
System (Example)

Example

127.548 = 1 x 82 + 2 x 81 + 7 x 80 + 5 x 8-1 + 4 x 8-
2

= 64 + 16 + 7 + 5/8 + 4/64

= 87 + 0.625 + 0.0625

= 87.687510

37
THANK YOU

38

You might also like