CS-chap02-Number Systems
CS-chap02-Number Systems
Systems
binary, octal and hexadecimal.
Convert a number in one system to another system.
Find the number of digits needed in each system to represent
a particular value.
2.1
Source: Foundations of Computer Science Cengage Learning 2.2
2-1 Introduction
2-2 Positional Number Systems
A number system defines how a number can be
In a positional number system, the position a symbol
represented using distinct symbols. A number can be
occupies in the number determines the value it
represented differently in different systems.
represents. In this system, a number represented as:
For example,
the two numbers (2A)16 and (52)8 both refer to the same
quantity, (42)10, but their representations are different. has the value of:
Example: (42)10
2.3 2.4
1
The Decimal System (base 10) Integers (base 10)
S = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
The symbols in this system are often referred to as decimal
digits or just digits. Example 2.1
The following shows the place values for the integer +224 in the
Different Systems decimal system.
Decimal: 0, …, 7, 8, 9, 10, 11, …
Octal: 0, …, 7, 10, 11, …, 16, 17, 20, 21, ..
Binary: 0, 1, 10, 11, 100, 101, 110, 111, 1000, …
2.5 2.6
The following shows the place values for the decimal number
−7508. We have used 1, 10, 100, and 1000 instead of powers of
10.
Example 2.3
( ) Values The following shows the place values for the real number +24.13.
2.7 2.8
2
The Binary System (base 2) Integers (base 2)
The word binary is derived from the Latin root bini (or two
by two). In this system the base b = 2 and we use only two
symbols,
S = {0, 1}
Example 2.4
The following shows that the number (11001)2 in binary is the
The symbols in this system are often referred to as binary same as 25 in decimal. The subscript 2 shows that the base is 2.
digits or bits (binary digit).
Example 2.5
S = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}
The following shows that the number (101.11)2 in binary is equal
to the number 5.75 in decimal.
3
Integers (base 16) The Octal System (base 8)
The word octal is derived from the Latin root octo (eight). In
this system the base b = 8 and we use eight symbols to
represent a number. The set of symbols is
S = {0, 1, 2, 3, 4, 5, 6, 7}
Example 2.6
The following shows that the number (2AE)16 in hexadecimal is
equivalent to 686 in decimal.
Example 2.7
The following shows that the number (1256)8 in octal is the same
as 686 in decimal.
4
Comparison of numbers in the Four Systems Conversion
We need to know how to convert a number in one system
to the equivalent number in another system. Since the
decimal system is more familiar than the other systems, we
first show how to covert from any base to decimal. Then
we show how to convert from decimal to any base. Finally,
we show how we can easily convert from binary to
hexadecimal or octal and vice versa.
2.17 2.18
Example 2.8
The following shows how to convert the binary number Note that the result in the decimal notation is not exact, because
(110.11)2 to decimal: (110.11)2 = 6.75. 3 × 16−2 = 0.01171875. We have rounded this value to three digits
(0.012).
2.19 2.20
5
Example 2.10 Decimal to Any Base (Integral part) – UML Diagram
2.21 2.22
Example 2.11
Convert 35 in decimal to binary, we start with the number in
decimal and move to the left while continuously finding the
quotients and the remainder of division by 2. The result is 35 =
(100011)2.
2.23 2.24
6
Example 2.13 Decimal to Any Base (Fractional part) – UML Diagram
2.25 2.26
2.27 2.28
7
Example 2.16 Example 2.17
2.29 2.30
Example 2.19
Show the hexadecimal equivalent of the binary number
(10011100010)2.
8
Example 2.20 Binary-Octal Conversion
Solution
Each hexadecimal digit is converted to 4-bit patterns:
The result is (001001001100)2. Show the octal equivalent of the binary number (101110010)2.
5 6 2 8
2.33 2.34
Solution
Write each octal digit as its equivalent bit pattern to get
2.35 2.36
9
Example 2.23
Find the minimum number of binary digits required to store
decimal integers with a maximum of six digits.
Solution
k = 6, b1 = 10, and b2 = 2. Then
2.37
10