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

COS1521-foundations_of_computer_science_-chapter_2

Uploaded by

Sootha Deea
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)
20 views

COS1521-foundations_of_computer_science_-chapter_2

Uploaded by

Sootha Deea
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/ 51

Foundations of Computer Science

Second Edition
BEHROUZ FOROUZAN
FIROUZ MOSHARRAF

Chapter 2
Number Systems

1
Outlines

z Introduction
z Positional Number Systems
– Base 10, 2, 8, 16.
z Nonpositional Number Systems
– Roman Numerals

2 CSIM@PU
Objectives

After studying this chapter, the student should


understand:
z The concept of number systems.
z Non-positional and positional number systems.
z Decimal, Binary, Hexadecimal and Octal system.
z Convert a number among binary, octal, hexadecimal,
and decimal systems.
z Find the number of digits needed in each system to
represent a particular value.
3 CSIM@PU
1-1 Introduction

4
The Definition of Number System

• A number can be represented using distinct


symbols and differently in different systems.
• For example,
• The two numbers (2A)16 and (52)8 both refer to
the same quantity, (42)10, but their
representations are different
• Two groups
• positional and non-positional systems

5 CSIM@PU
1-2 Position Number Systems

6
Overview

z In a positional number system, a number


represented as:

has the value of:

in which S is the set of symbols, b is the base (or radix).


The Base includes Base10(Decimal), Base2(Binary), Base
16(Hexadecimal), or Base8(octal)。
7 CSIM@PU
The decimal system (base 10)

z The word decimal is derived from the Latin


root decem (ten).
– base b = 10, and
– ten symbols: S = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
z The symbols in this system are often referred
to as decimal digits or just digits.
– Integer examples
– Real examples

8
Base 10 – Integers (1)

Figure 2.1 Place values for an integer in the decimal system

9
Base 10 – Integers (2)

z Example 2.1 shows the place values for the integer


+224 in the decimal system

z Example 2.2 shows the place values for the decimal


number −7508

( ) Values
10
Base 10 – Reals

z A real – a number with a fractional part

z Example 2.3 shows the place values for the


real number +24.13.

11
The binary system (base 2)

z The word binary is derived from the Latin


root bini (or two by two).
– base b = 2, and
– two symbols, S = {0, 1}
z The symbols in this system are often referred
to as binary digits or bits (binary digit).
– Integer examples
– Real examples

12
Base 2 – Integers (1)

z We can represent an Integer as:

Figure 2.2 Place values for an integer in the binary system


13
Base 2 – Integers (2)

z Example 2.4 shows that the number (11001)2


in binary is the same as 25 in decimal. The
subscript 2 shows that the base is 2.

The equivalent decimal number is N = 16 + 8 + 0 + 0 + 1 = 25.

14
Base 2 – Reals (1)

z Example 2.5 shows that the number (101.11)2


in binary is equal to the number 5.75 in
decimal.

The equivalent decimal number is R = 4+0+1+0.5+0.25 = 5.75.


15
The hexadecimal system (base 16)

z The word hexadecimal is derived from the Greek


root hex (six) and the Latin root decem (ten).
– base b = 16, and
– sixteen symbols,
S = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}

z Symbol A, B, C, D, E, F are equivalent to 10, 11, 12,


13, 14, and 15 respectively.
z The symbols in this system are often referred to as
hexadecimal digits.

16
Base 16 – Integers (1)

z We can represent an Integer as:

Figure 2.3 Place values for an integer in the hexadecimal system


17
Base 16 – Integers (2)

z Example 2.6 shows that the number (2AE)16


in hexadecimal

The equivalent decimal number is N = 512 + 160 + 14 = 686.

18
The octal system (base 8)

z The word octal is derived from the Latin root


octo (eight).
– base b = 8, and
– Eight symbols, S = {0, 1, 2, 3, 4, 5, 6, 7}
z Place values for an integer in the octal system

19
Base 8 – Integers (1)

z We can represent an Integer as:

Figure 2.4 Place values for an integer in the octal system

20
Base 8 – Integers (2)

z Example 2.7 shows that the number (1256)8


in octal is the same as 686 in decimal.

The decimal number is N = 512 + 128 + 40 + 6 = 686.

21
Summary of the Base 10/2/8/16
positional systems (1)

22
Summary (2)

The number 0 to
15 is represented
in different
systems

23
Conversion

z The decimal system is more familiar than the


other systems
z To convert a number in one system to the
equivalent number in another system
– Any base – Decimal
– Binary – Hexadecimal
– Binary – Octal
– Octal – Hexadecimal

24
Any base to decimal conversion (1)

z Converting other bases to decimal (Fig. 2.5)

25
Any base to decimal conversion (2)

z Example 2.8 shows how to convert the binary


number (110.11)2 to decimal: (110.11)2 =
6.75.

26
Any base to decimal conversion (3)

z Example 2.9 shows how to convert the


hexadecimal number (1A.23)16 to decimal.

The result in the decimal notation is not exact, because


3 × 16−2 = 0.01171875. We have rounded this value to three
digits (0.012).
27
Any base to decimal conversion (4)

z Example 2.10 shows how to convert (23.17)8


to decimal.

This means that (23.17)8 ≈ 19.234 in decimal. Again, we have


rounded up 7 × 8−2 = 0.109375.

28
Decimal to any base conversion

z Two procedures for converting a decimal


number to its equivalent in any base.
– Converting the integral part
– Converting the fractional part

29
Converting the integral part (1)

UML’s state diagram

30
Converting the integral part (2)

z The Figure shows the destination is made


with each repetition. (process manually)

Figure 2.7
31 Converting the integral part of a number in decimal to other bases
Converting the integral part (3)

z Example 2.11 shows how to convert 35 in decimal to


binary. The result is 35 = (100011)2.

z Example 2.12 shows how to convert 126 in decimal


to octal. The result is 126 = (176)8.

32
Converting the integral part (4)

z Example 2.13 shows how to convert 126 in


decimal to hexadecimal. The result is 126 =
(7E)16

33
Converting the fractional part (1)

UML’s
State
diagram

34
Converting the fractional part (2)

z The Figure shows the destination is made with each


repetition. (process manually)

Figure 2.9
35 Converting the fractional part of a number in decimal to other bases
Converting the fractional part (3)

z Example 2.14 converts the decimal number


0.625 to binary.

Since the number 0.625 = (0.101)2 has no integral part, the


example shows how the fractional part is calculated.

36
Converting the fractional part (4)

z Example 2.15 shows how to convert 0.634 to octal using


a maximum of four digits. The result is 0.634 = (0.5044)8.

z Example 2.16 shows how to convert 178.6 in decimal to


hexadecimal using only one digit to the right of the
decimal point. The result is 178.6 = (B2.9)16

37
Converting the fractional part (5)

z An alternative method for converting a small


decimal integer (< 256) to binary is to break
the number as the sum of numbers that are
equivalent to the binary place values shown:

For Example:

38
Converting the fractional part (6)

z A method can be used to convert a decimal fraction


to binary when the denominator is a power of two:
z Convert 27/64 to binary: The answer is (0.011011)2

39
Binary-hexadecimal conversion (1)

z A relationship between the two bases: four


bits in binary is one digit in hexadecimal

Figure 2.10
Binary to hexadecimal and hexadecimal to binary conversion
40
Binary-hexadecimal conversion (2)

z Example 2.19 shows the hexadecimal equivalent of


the binary number (110011100010)2.

100 1110 0010


– First, arranging the binary number in 4-bit patterns
– Using the equivalent of each pattern shown in Table
2.2 on page 25
– Then, changing the number to hexadecimal:
(4E2)16.
41
Binary-hexadecimal conversion (3)

z Example 2.20: What is the binary equivalent


of (24C)16?
z Each hexadecimal digit is converted to 4-bit
patterns. The result is (001001001100)2.

2 → 0010, 4 → 0100, and C → 1100

42
Binary-octal conversion (1)

z A relationship between the two bases: three


bits in binary is one octal digit

Figure 2.10 Binary to octal and octal to binary conversion


43
Binary-octal conversion (2)

z Example 2.21 shows the octal equivalent of the


binary number (101110010)2.
– Each group of three bits is translated into one octal digit
(Table 2.2). The result is (562)8.
101 110 010
z Example 2.22: What is the binary equivalent of for
(24)8?
– Write each octal digit as its equivalent bit pattern to get. The
result is (010100)2.

44 2 → 010 and 4 → 100


Octal-hexadecimal conversion (1)

z Using the binary system as the intermediate


system.

Figure 2.12
Octal to hexadecimal and hexadecimal to octal conversion
45
Octal-hexadecimal conversion (2)

z Example 2.23 – to find the minimum number of


binary digits required to store decimal integers with a
maximum of six digits.
– k = 6, b1 = 10, and b2 = 2. Then

x = ⎡k × (logb1 / logb2)⎤ = ⎡6 × (1 / 0.30103)⎤ = 20.


– The largest six-digit decimal number is 999,999.
– The largest 20-bit binary number is 1,048,575.
– The largest 19-bit number is 524287, which is smaller than
999,999.
– We definitely need twenty bits.
46
1-3 Nonpositional Number
Systems

47
Overview (1)

• Non-positional number systems are not


used in computers.
• A non-positional number system still uses a
limited number of symbols in which each
symbol has a value.
• We give a short review for comparison with
positional number systems.

48
Overview (2)

z A number is represented as:

and has the value of:

Some exceptions to the addition rule, as shown in


49 Example 2.24 (Roman Numerals).
Roman numerals

z Roman numerals is a non-positional number system


– The set of symbols, S = {I, V, X, L, C, D, M}.
– Table 2.3 shows the values of each symbol

z To find the value of a number, we need to add the value


of symbols subject to specific rules (See Page 34).
50
Roman numerals and their values

51

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy