0% found this document useful (0 votes)
16 views20 pages

04_numberSystem

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

04_numberSystem

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

Programming for

Engineers

Number System
ICEN 200 – Spring 2018
Prof. Dola Saha
1
Types of Numbers
Ø Natural Numbers
§ The number 0 and any number obtained by repeatedly adding a count
of 1 to 0
Ø Negative Numbers
§ A value less than 0
Ø Integer
§ A natural number, the negative of a natural number, and 0.
§ So an integer number system is a system for ‘counting’ things in a
simple systematic way

2
Exponent Review
Ø An exponent (power) tells you how many times to multiply the base by
itself:
§ 21 = 2
§ 22 = 2 x 2 =4
§ 23 = 2 x 2 x 2 = 8

Ø 20 = 1 (ANY number raised to power 0 is 1)


Ø 1 / x2 = x -2

3
Decimal Number System
Ø How is a positive integer represented in decimal?
Ø Let’s analyze the decimal number 375:
375 = (3 x 100) + (7 x 10) + (5 x 1)
= (3 x 102) + (7 x 101) + (5 x 100)

Position weights 102 101 100


Number digits 3 7 5
5 x100 = 5 +
7 x101 = 70 +
3 x 102 = 300
375

4
Bits
Ø In a computer, information is stored using digital signals that translate
to binary numbers

Ø A single binary digit (0 or 1) is called a bit

§ A single bit can represent two possible states, on (1) or off (0)

Ø Combinations of bits are used to store values

5
Data Representation
Ø Data representation means encoding data into bits
§ Typically, multiple bits are used to represent the ‘code’ of each value
being represented

Ø Values being represented may be characters, numbers, images, audio


signals, and video signals.

Ø Although a different scheme is used to encode each type of data, in the


end the code is always a string of zeros and ones

6
Decimal to Binary
Ø So in a computer, the only possible digits we can use to encode data are
{0,1}

§ The numbering system that uses this set of digits is the base 2 system
(also called the Binary Numbering System)

Ø We can apply all the principles of the base 10 system to the base 2
system

Position weights 24 23 22 21 20
digits 1 0 1 1

7
Binary Numbering System
Ø How is a positive integer represented in binary?
Ø Let’s analyze the binary number 110:
110 = (1 x 22) + (1 x 21) + (0 x 20)
= (1 x 4) + (1 x 2) + (0 x 1)

Position weights 22 21 20
Number digits 1 1 0
0 x20 = 0 +
1 x21 = 2 +
1 x 22 = 4
6

Ø So a count of SIX is represented in binary as 110


8
Binary to Decimal Conversion

Example: Convert binary 100101 to decimal


(written 1 0 0 1 0 12 ) =
1*20 + 1+
0*21 +
1*22 + 4+
0*23 +
0*24 +
1*25 32
3710
9
Binary to Decimal Conversion

Example #2: 101112

positional powers of 2: 24 23 22 21 20
decimal positional value: 16 8 4 2 1
binary number: 1 0 1 1 1

16 + 4 + 2 + 1 = 2310

10
Binary to Decimal Conversion

Example #3: 1100102

positional powers of 2: 25 24 23 22 21 20
decimal positional value: 32 16 8 4 2 1
binary number: 1 1 0 0 1 0

32 + 16 + 2 = 5010

11
Decimal to Binary Conversion

Using the Division Method:


Divide decimal number by 2 until you reach zero, and then
collect the remainders in reverse.
Example 1: 2210 = 101102

2 ) 22 Rem:
2 ) 11 0
2 ) 5 1
2 ) 2 1
2 ) 1 0
0 1

12
Decimal to Binary Conversion

Using the Division Method


Example 2: 5610 = 111000
2

2 ) 56 Rem:
2 ) 28 0
2 ) 14 0
2 ) 7 0
2 ) 3 1
2 ) 1 1
0 1

13
Octal Number
Ø Base: 8
Ø Digits: 0, 1, 2, 3, 4, 5, 6, 7
n Octal number: 3578

= (3 x 82 ) + (5 x 81) + (7 x 80)

Ø To convert to base 10, beginning with the rightmost


digit, multiply each nth digit by 8(n-1), and add all of
the results together.

14
Octal to Decimal Conversion
§ Example 1: 3578

positional powers of 8: 82 81 80
decimal positional value: 64 8 1
Octal number: 3 5 7

(3 x 64) + (5 x 8) + (7 x 1)

= 192 + 40 + 7 = 23910

15
Decimal to Octal Conversion
Using the Division Method:

Example 1: 21410 = 3268

8 ) 214 Rem:
8 ) 26 6
8) 3 2
0 3

16
Hexadecimal Number
Ø Base: 16

Ø Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

Ø Hexadecimal number: 1F416

= (1 x 162 ) + (F x 161) + (4 x 160)

17
Hex Values

Decimal Value Hexadecimal Digit


10 A
11 B
12 C
13 D
14 E
15 F

18
Hex to Decimal Conversion
Ø Example 1: 1F416

positional powers of 16: 163 162 161 160


decimal positional value: 4096 256 16 1

Hexadecimal number: 1 F 4

(1 x 256) + (F x 16) + (4 x 1)
= (1 x 256) + (15 x 16) + (4 x 1)

= 256 + 240 + 4 = 50010


19
Decimal to Hex Conversion

Using The Division Method:


Example 1: 12610 = 7E16

16) 126 Rem:


16) 7 14=E
0 7

20

You might also like