You are on page 1of 99

Chapter 9

Number Systems

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


+
The Decimal System
 System based on decimal digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) to represent
numbers

 For example the number 83 means eight tens plus three:

83 = (8 * 10) + 3

 The number 4728 means four thousands, seven hundreds, two tens, plus
eight:

4728 = (4 * 1000) + (7 * 100) + (2 * 10) + 8


 The decimal system is said to have a base, or radix, of 10. This means that
each digit in the number is multiplied by 10 raised to a power
corresponding to that digit’s position:

83 = (8 * 101) + (3 * 100)

4728 = (4 * 103) + (7 * 102) + (2 * 101) + (8 * 100)


© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
+
Decimal Fractions
 The same principle holds for decimal fractions, but negative powers of 10 are
used. Thus, the decimal fraction 0.256 stands for 2 tenths plus 5 hundredths
plus 6 thousandths:

0.256 = (2 * 10-1) + (5 * 10-2) + (6 * 10-3)

 A number with both an integer and fractional part has digits raised to both
positive and negative powers of 10:

442.256 = (4 * 102) + (4 + 101) + (2 * 100) + (2 * 10-1) + (5 * 10-2)

+ (6 * 10-3)

 Most significant digit


 The leftmost digit (carries the highest value)

 Least significant digit


 The rightmost digit
© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Table 9.1
Positional Interpretation of a Decimal Number

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


+
Common Number Systems

Used by Used in
System Base Symbols humans? computers?
Decimal 10 0, 1, … 9 Yes No
Binary 2 0, 1 No Yes
Octal 8 0, 1, … 7 No No
Hexa- 16 0, 1, … 9, No No
decimal A, B, … F
+
Quantities/Counting (1 of 3)
Hexa-
Decimal Binary Octal decimal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
p. 33
+
Quantities/Counting (2 of 3)
Hexa-
Decimal Binary Octal decimal
8 1000 10 8
9 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
+
Quantities/Counting (3 of 3)
Hexa-
Decimal Binary Octal decimal
16 10000 20 10
17 10001 21 11
18 10010 22 12
19 10011 23 13
20 10100 24 14
21 10101 25 15
22 10110 26 16
23 10111 27 17 Etc.
+
Conversion Among Bases

 The possibilities:

Decimal Octal

Binary Hexadecimal
+ The Binary System
 Only two digits, 1 and 0

 Represented to the base 2

 The digits 1 and 0 in binary notation have the same meaning as in decimal notation:

02 = 010

12 = 110

 To represent larger numbers each digit in a binary number has a value depending on
its position:

102 = (1 * 21) + (0 * 20) = 210

112 = (1 * 21) + (1 * 20) = 310

1002 = (1 * 22) + (0 * 21) + (0 * 20) = 410

and so on. Again, fractional values are represented with negative powers of the radix:

1001.101 = 23 + 20 + 2-1 + 2-3 = 9.62510

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


+
Numbers Are Different!

 Computers use binary (not decimal) numbers (0's and 1's).


 Requires more digits to represent the same magnitude.

 Computers store and process numbers using a fixed


number of digits (“fixed-precision”).

 Computers represent signed numbers using 2's


complement instead of sign-plus-magnitude (not our
familiar “sign-plus-magnitude”).

Copyright © 2000, Daniel W. Lewis. All Rights Reserved.


+
Positional Number Systems

 Numeric values are represented by a sequence of


digit symbols.

 Symbols represent numeric values.


 Symbols are not limited to ‘0’-’9’!

 Each symbol’s contribution to the total value of the


number is weighted according to its position in the
sequence.
Copyright © 2000, Daniel W. Lewis. All Rights Reserved.
+ Polynomial Evaluation

Whole Numbers (Radix = 10):


123410 = 1  103 + 2  102 + 3  101 + 4  100

With Fractional Part (Radix = 10):


36.7210 = 3  101 + 6  100 + 7  10-1 + 2  10-2

General Case (Radix = R):


(S1S0.S-1S-2)R =

S1  R1 + S0  R0 + S-1  R -1 + S-2  R-2

Copyright © 2000, Daniel W. Lewis. All Rights Reserved.


+
Converting Radix R to Decimal

36.728 = 3  81 + 6  80 + 7  8-1 + 2  8-2

= 24 + 6 + 0.875 + 0.03125
= 30.9062510

Important: Polynomial evaluation doesn’t work if you try to


convert in the other direction – I.e., from decimal to
something else! Why?

Copyright © 2000, Daniel W. Lewis. All Rights Reserved.


+
Decimal to Binary

Decimal Octal

Binary Hexadecimal
+ Decimal to Binary Conversion
(Whole Part: Repeated Division)

 Divide by target radix (2 in this case)

 Remainders become digits in the new representation (0 <= digit < R)

 Digits produced in right to left order.

 Quotient is used as next dividend.

 Stop when the quotient becomes zero, but use the corresponding
remainder.

Copyright © 2000, Daniel W. Lewis. All Rights Reserved.


+ Decimal to Binary Conversion
(Whole Part: Repeated Division)

 97  2  quotient = 48, remainder = 1 (LSB)


48  2  quotient = 24, remainder = 0.
24  2  quotient = 12, remainder = 0.
12  2  quotient = 6, remainder = 0.
6  2  quotient = 3, remainder = 0.
3  2  quotient = 1, remainder = 1.
1  2  quotient = 0 (Stop) remainder = 1 (MSB)

 Result = 1 1 0 0 0 0 12

Copyright © 2000, Daniel W. Lewis. All Rights Reserved.


+ Decimal to Binary Conversion
(Fractional Part: Repeated Multiplication)

.1  2  0.2 (fractional part = .2, whole part = 0)


.2  2  0.4 (fractional part = .4, whole part = 0)
.4  2  0.8 (fractional part = .8, whole part = 0)
.8  2  1.6 (fractional part = .6, whole part = 1)
.6  2  1.2 (fractional part = .2, whole part = 1)

Result = .00011001100110011 2…..

(How much should we keep?)

Copyright © 2000, Daniel W. Lewis. All Rights Reserved.


Decimal to Binary Conversion Example
Use the chart to record the division

1 0 1 1 1 1 0 1 = 189
To convert the decimal 189 / 2 = 94 r 1
number 189 to binary 94 / 2 = 47 r 0
you must divide the 47 / 2 = 23 r 1
number by 2. Starting 23 / 2 = 11 r 1
from the right, place a 11 / 2 = 5 r 1
1 if there is a 5/2= 2r1
remainder or a 0 if no 2/2= 1r0
remainder. 1 / 2 = cannot
divide further -
carry the 1 Press any key to continue…
Decimal to Binary Conversion Example
Use the chart to record the division

0 1 0 0 1 0 1 1 = 75
To convert the decimal 75 / 2 = 37 r 1
number 75 to binary 37 / 2 = 18 r 1
you must divide the 18 / 2 = 9 r 0
number by 2. Starting 9/2= 4r1
from the right, place a 4/2= 2r0
1 if there is a 2/2= 1r0
remainder or a 0 if no 1 / 2 = cannot divide
remainder. further - carry the 1
Fill in to make 8 bits with 0
Press any key to continue…
Decimal to Binary Conversion Example
Use the chart to record the division

1 1 1 1 0 0 1 0 = 242
To convert the decimal 242 / 2 = 121 r 0
number 242 to binary 121 / 2 = 60 r 1
you must divide the 60 / 2 = 30 r 0
number by 2. Starting 30 / 2 = 15 r 0
from the right, place a 15 / 2 = 7 r 1
1 if there is a 7/2= 3r1
remainder or a 0 if no 3/2= 1r1
remainder. 1 / 2 = cannot
divide further -
carry the 1 Press any key to continue…
+ Counting in Binary

Dec Binary Note the pattern!


0 0000 • LSB (bit 0) toggles on
1 0001 every count.
2 0010 • Bit 1 toggles on every
3 0011 second count.
4 0100 • Bit 2 toggles on every
5 0101 fourth count.

6 0110 • Etc….

7 0111

Copyright © 2000, Daniel W. Lewis. All Rights Reserved.


© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
+
Example
12510 = ?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
Figure 9.2
Examples of
Converting
from
Decimal Notation
To
Binary Notation
For Fractions

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


+
Binary to Decimal

Decimal Octal

Binary Hexadecimal
+
Binary to Decimal

 Technique

Multiply each bit by 2n, where n is the “weight” of the bit
 The weight is the position of the bit, starting from 0 on the right
 Add the results
+
Example
Bit “0”

1010112 => 1 x 20 = 1
1 x 21 = 2
0 x 22 = 0
1 x 23 = 8
0 x 24 = 0
1 x 25 = 32
4310
+
Binary to Decimal Conversion

Converting to decimal, so we can use polynomial evaluation:

101101012

= 127 + 026 + 125 + 124 + 023 + 122 + 021 +


120

= 128 + 32 + 16 + 4 + 1

= 18110

Copyright © 2000, Daniel W. Lewis. All Rights Reserved.


+ 30

Binary → Dec : Example #2


Example:
Convert the binary number 01101012 into its decimal
equivalent.
Solution:

0 1 1 0 1 0 1
26 25 24 23 22 21 20

64 32 16 8 4 2 1

0 + 32 + 16 + 0 + 4 + 0 + 1 = 5310

\01101012 = 5310
+ 31

Binary → Dec : More Examples

a) 0110 2 = ?

b) 11010 2 = ?

c) 0110101 2 = ?

d) 11010011 2 = ?

e) 10.1011 2 = ?
+ 32

Binary → Dec : More Examples

a) 0110 2 = ? 6 10

b) 11010 2 = ? 26 10

c) 0110101 2 = ? 53 10

d) 11010011 2 = ? 211 10
+
Dec → Binary : Examples

Convert the following decimal numbers to


binary.
A. 45
B. 69
C. 99
E. 1
+
Dec → Binary : Examples
Answers
 Binary

A. 101101
B. 1000101
C. 1100011
D. 1
+
Octal to Binary

Decimal Octal

Binary Hexadecimal
+
Octal to Binary

 Technique
 Convert each octal digit to a 3-bit equivalent binary representation
+
Use the Table for conversion
Hexa-
Decimal Binary Octal decimal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
p. 33
+
Example
7058 = ?2

7 0 5

111 000 101

7058 = 1110001012
+
Converting Octal to Binary

435208 = 1000111010100002
STEP ONE: Take each octal digit and
convert each digit to a binary triplet. Keep
leading zeros:
4 3 5 2 0
100 011
0 101 010
0 000

39
+
Binary to Octal

Decimal Octal

Binary Hexadecimal
+
Binary to Octal

 Technique
 Group bits in threes, starting on right
 Convert to octal digits
+
Example
10110101112 = ?8

1 011 010 111

1 3 2 7

10110101112 = 13278
+Converting Binary to Octal

start
100011001010012
STEP ONE: Take the binary number and
from right to left, group all placeholders in
triplets. Add leading zeros, if necessary:

010 001 100 101 001

43
+
0010 001 100 101 0012 = 214518

STEP TWO: Convert each triplet to its


single-digit octal equivalent. (HINT: For
each triplet, the octal conversion is the
same as converting to a decimal number):
010 001 100 101 001
2 1 4 5 1
44
+ Exercise 1 - Binary to Octal
 Covert the following Binary to Octal :

A. 111110110

B. 1000001

C. 10000010

D. 1100010

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


+
Use the Table for conversion
Hexa-
Decimal Binary Octal decimal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
p. 33
+ Exercise 1 - Solutions
 Covert the following Binary to Octal :

A. 766

B. 202

C. 101

D. 142

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


+ Exercise 2 – Octal to Binary
 Covert the following Octal to Binary:

A. 25248

B. 3322108

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


+
Use the Table for conversion
Hexa-
Decimal Binary Octal decimal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
p. 33
+ Exercise 2 – Octal to Binary
 Covert the following Octal to Binary :

A. 25248 = 010101010100

B. 3322108 = 011011010010001000

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


+
Octal to Decimal

Decimal Octal

Binary Hexadecimal
+
Octal to Decimal

 Technique

Multiply each bit by 8n, where n is the “weight” of the bit
 The weight is the position of the bit, starting from 0 on the right
 Add the results
+
Example

7248 => 4 x 80 = 4
2 x 81 = 16
7 x 82 = 448
46810
+
Octal to Decimal

Decimal Octal

Binary Hexadecimal
+ Decimal to Octal
 Step 1: Take the given decimal number

 Step 2: If the number is less than 8 the octal number is the same

 Step 3: If the number is greater than 7 then Divide the number
with 8

 Step 4: Note the remainder

 Step 5: Carry on the step 3 and 4 with the qoutient till it is less
than 8

 Step 6: Write the remainders in reverse order(bottom to top)

 Step 7: The resultant is the equivalent octal number to the given


decimal number

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


+ Decimal to Octal
 Question 1: Convert 128 to octal form.
Solution: Given decimal number is 128

 Start the division process

 8 | 128
8 | 16 -- 0
8 | 2 -- 0
8 | 0 --2

 The equivalent octal number for 128 is 2008

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


+ Decimal to Octal
 Question 2: Convert 58 to octal form
Solution: Given decimal number is 58

 Start the division process

 8 | 58

8 | 7 -- 2

8 | 0 --7

 octal number for 58 is 728

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


+ Decimal to Octal
 Question 3: Convert 451 to octal form
Solution:

 Given decimal number is 451

 Start the division process

 8 | 451

 8 | 56 -- 3

 8 | 7 -- 0

 8 | 0 -- 7

 the equivalent octal number for 128 is 7038

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


+ Decimal to Octal
 Question 4: Convert 4 to octal form?
Solution: Given decimal number is 4

 Since 4 is less than 7

 Correct answer is the equivalent octal number for 4 is 48

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


+ Exercise 1 - Decimal to Octal
 Covert the following Decimal to Octal:

A. 901

B. 321

C. 112

D. 25.625

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


+ Exercise 1 - Decimal to Octal
 Covert the following Decimal to Octal :

A. 901 = 1605

B. 321 = 501

C. 112 = 160

D. 25.625 = 31.50

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


+ Exercise 2 - Octal to Decimal
 Covert the following Octal numbers to Decimals:

 777

 345

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


+ Exercise 2 - Octal to Decimal
 Covert the following Octal numbers to Decimals:

 777 = 511

 345 = 229

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


+
Hexadecimal Notation
 Binary digits are grouped into sets of four bits, called a nibble

 Each possible combination of four binary digits is given a symbol, as follows:

0000 = 0 0100 = 4 1000 = 8 1100 = C


0001 = 1 0101 = 5 1001 = 9 1101 = D
0010 = 2 0110 = 6 1010 = A 1110 = E
0011 = 3 0111 = 7 1011 = B 1111 = F

 Because 16 symbols are used, the notation is called hexadecimal and the 16
symbols are the hexadecimal digits

 Thus

2C16 = (216 * 161) + (C16 * 160)

= (210 * 161) + (1210 * 160) = 44


© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
+ Hexadecimal Numbers
(Radix = 16)

 The number of digit symbols is determined by the


radix (e.g., 16)
 The value of the digit symbols range from 0 to 15 (0
to R-1).
 The symbols are 0-9 followed by A-F.
 Conversion between binary and hex is trivial!
 Use as a shorthand for binary (significantly fewer
digits are required for same magnitude).

Copyright © 2000, Daniel W. Lewis. All Rights Reserved.


+ Know this table!
Hex Binary Hex Binary
0 0000 8 1000
1 0001 9 1001
2 0010 A 1010
3 0011 B 1011
4 0100 C 1100
5 0101 D 1101
6 0110 E 1110
7 0111 F 1111

Copyright © 2000, Daniel W. Lewis. All Rights Reserved.


+
Binary to Hexadecimal

Decimal Octal

Binary Hexadecimal
+
Binary to Hexadecimal

 Technique
 Group bits in fours, starting on right
 Convert to hexadecimal digits
+
Example
10101110112 = ?16

10 1011 1011

2 B B

10101110112 = 2BB16
+ Binary/Hex Conversions

Hex digits are in one-to-one correspondence with groups of four


binary digits:
11 1010 0101 0110 . 1110 0010 1111 1000
3 A 5 6 . E 2 F 8
• Conversion is a simple table lookup!
• Zero-fill on left and right ends to complete the groups!
• Works because 16 = 24 (power relationship)

Copyright © 2000, Daniel W. Lewis. All Rights Reserved.


+

Table 9.3

Decimal, Binary,
and Hexadecimal

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.


+
Hexadecimal to Binary

Decimal Octal

Binary Hexadecimal
+ Hexadecimal to Binary Conversions

Remember hexadecimal uses groups of four bits, so we can use


the table below for conversions.
Examples:
To convert D14B to binary:
D = 1101, 1 = 0001, 4 = 0100, B = 1011
When we put the pieces together, we get: D14B16 =
11010001010010112
+ Hexadecimal to Binary Examples

Hex to binary conversion examples

 (1E3)16 = (0001 1110 0011)2

 (0A2B)16 = (0000 1010 0010 1011)2

 (7E0C)16 = (0111 1110 0000 1100) 2


+
Exercise 1 Hexadecimal
 Convert the following binary numbers to hexadecimal.
A. 10101001

B. 11100111

C. 01101110
+
Exercise 2 Hexadecimal

Express each number as a binary number.


b. BAC916
d. 4009D16
+
Hexadecimal to Decimal

Decimal Octal

Binary Hexadecimal
+
Hexadecimal to Decimal

 Technique

Multiply each bit by 16n, where n is the “weight” of the bit
 The weight is the position of the bit, starting from 0 on the right
 Add the results
+
Example

ABC16 => C x 160 = 12 x 1 = 12


B x 161 = 11 x 16 = 176
A x 162 = 10 x 256 = 2560
274810
+
Example
Convert 7DE hex number to a decimal

7DE = (7 * 16^2) + (13 * 16^1) + (14 * 16^0)

7DE = (7 * 256) + (13 * 16) + (14 * 1)

7DE = 1792 + 208 + 14

7DE = 2014 (in decimal number)


+
Exercise 1. Hexadecimal to Decimal

 Cover the following Hex to decimal:

 (1D9)16 =

 (80E1)16 =

 (10CE)16 =
+ Use this table
Hex Binary Hex Binary
0 0000 8 1000
1 0001 9 1001
2 0010 A 1010
3 0011 B 1011
4 0100 C 1100
5 0101 D 1101
6 0110 E 1110
7 0111 F 1111

Copyright © 2000, Daniel W. Lewis. All Rights Reserved.


+
Exercise 1. Hexadecimal to Decimal

 Solutions

 (1D9)16 = (473)10

 (80E1)16 = (32993)10

 (10CE)16 = (4302)10
+
Decimal to Hexadecimal

Decimal Octal

Binary Hexadecimal
+
Decimal to Hexadecimal
 Steps

1. Divide the decimal number by 16. Treat the division as an


integer division.

2. Write down the remainder (in hexadecimal).

3. Divide the result again by 16. Treat the division as an integer


division.

4. Repeat step 2 and 3 until result is 0.

5. The hex value is the digit sequence of the remainders from the
last to firs
+
Decimal to Hexadecimal
 Convert the number 256 DECIMAL to HEXADECIMAL

DIVISION RESULT REMAINDER (in HEX)

256 / 16 16 0
16 / 16 1 0
1 / 16 0 1
     
ANSWER   100
+
Decimal to Hexadecimal
 Convert the number 921 DECIMAL to HEXADECIMAL

DIVISION RESULT REMAINDER (in HEX)

921 / 16 57 9

57 / 16 3 9
3 / 16 0 3
     

ANSWER   399
+
Decimal to Hexadecimal
 Convert the number 188 DECIMAL to HEXADECIMAL

REMAINDER
DIVISION RESULT
(in HEX)

188 / 16 11 C (12 decimal)

11 / 16 0 B (11 decimal)
     

ANSWER   BC
+
Decimal to Hexadecimal
 Convert the number decimals to Hexadecimal:

 100 =

 590 =

 998 =
+ Use this table
Hex Binary Hex Binary
0 0000 8 1000
1 0001 9 1001
2 0010 A 1010
3 0011 B 1011
4 0100 C 1100
5 0101 D 1101
6 0110 E 1110
7 0111 F 1111

Copyright © 2000, Daniel W. Lewis. All Rights Reserved.


+
Decimal to Hexadecimal
 Solution:

 100 = 64

 590 = 24E

 998 = 3E6
+
Decimal to Hexadecimal
 Technique
 Group bits in fours, starting on right
 Convert to hexadecimal digits
+
Recap - Fractions

 Decimal to decimal (just for fun)

3.14 => 4 x 10-2 = 0.04


1 x 10-1 = 0.1
3 x 100 = 3
3.14

pp. 46-50
+
Recap - Fractions

 Binary to decimal
10.1011 => 1 x 2-4 = 0.0625
1 x 2-3 = 0.125
0 x 2-2 = 0.0
1 x 2-1 = 0.5
0 x 20 = 0.0
1 x 21 = 2.0
2.6875

pp. 46-50
+
Recap - Fractions
 Decimal to binary .14579
x 2
3.14579 0.29158
x 2
0.58316
x 2
1.16632
x 2
0.33264
x 2
0.66528
x 2
1.33056
11.001001... etc.

p. 50
+
Home Exercise
Complete the table below
Hexa-
Decimal Binary Octal decimal
29.8
101.1101
3.07
C.82
+
Exercise – Convert …
Answer

Hexa-
Decimal Binary Octal decimal
29.8 11101.110011… 35.63… 1D.CC…
5.8125 101.1101 5.64 5.D
3.109375 11.000111 3.07 3.1C
12.5078125 1100.10000010 14.404 C.82
+
Summary Conversion

 The possibilities:

Decimal Octal

Binary Hexadecimal
+ Summary
Number Systems

Chapter 9
 Convertingbetween types
 The decimal system of number systems
 Positional number
systems
 The binary system

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

You might also like