Number Systems
CS205 Computer Organization and Architecture - Number Systems
Acknowledgments
These materials are based on William Stallings' "Computer Organization and Architecture," 10th Edition.
Corresponds to Chapter 9.
Chapter 02: Number Systems
Objectives
Understand basic concepts and terminology of positional number systems.
Explain techniques for converting between decimal and binary for integers and fractions.
Explain the rationale for using hexadecimal notation.
The Decimal System
Based on decimal digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) to represent numbers.
Example: 83 means eight tens plus three:
Example: 4728 means four thousands, seven hundreds, two tens, plus eight:
The decimal system has a base, or radix, of 10.
Each digit in the number is multiplied by 10 raised to a power corresponding to that digit’s position.
Decimal Fractions
Same principle applies to decimal fractions, but negative powers of 10 are used.
A number with both an integer and fractional part has digits raised to both positive and negative powers of 10.
Most significant digit:
The leftmost digit, carries the highest value.
Least significant digit:
The rightmost digit.
Positional Interpretation of a Decimal Number
Example:
472.256
4 is in the 100s place ().
7 is in the 10s place ().
2 is in the 1s place ().
2 is in the tenths place ().
5 is in the hundredths place ().
6 is in the thousandths place ().
Positional Number Systems
Each number is represented by a string of digits in which each digit position has an associated weight , where is the radix, or base, of the number system.
The general form of a number in such a system with radix is:
The value of any digit is an integer in the range . The dot between and is the radix point.
Positional Interpretation of a Number in Base 7
Example:
Position 4: Value in exponential form is , Decimal value is 2401.
Position 3: Value in exponential form is , Decimal value is 343.
Position 2: Value in exponential form is , Decimal value is 49.
Position 1: Value in exponential form is , Decimal value is 7.
Position 0: Value in exponential form is , Decimal value is 1.
Position -1: Value in exponential form is , Decimal value is 1/7.
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:
To represent larger numbers, each digit in a binary number has a value depending on its position:
Fractional values are represented with negative powers of the radix:
Converting Between Binary and Decimal
Binary notation to decimal notation:
Multiply each binary digit by the appropriate power of 2 and add the results.
Decimal notation to binary notation:
Integer and fractional parts are handled separately.
Integers
In binary notation, an integer represented by , where or 1, has the value:
To convert a decimal integer into binary form:
Divide by 2, obtaining a quotient and a remainder . Then: , where or 1.
Divide the quotient by 2. Assume that the new quotient is and the new remainder is . Then: , where or 1.
So,
If , then
Continued…
Because , continuing this sequence will eventually produce a quotient (except for the decimal integers 0 and 1, whose binary equivalents are 0 and 1, respectively) and a remainder , which is 0 or 1.
Then , which is the binary form of .
Convert from base 10 to base 2 by repeated divisions by 2.
The remainders and the final quotient, 1, give us, in order of increasing significance, the binary digits of .
Fractions
In binary notation, a number with a value between 0 and 1 is represented by , where or 1, and has the value:
This can be rewritten as:
To convert the number () from decimal to binary notation, we know that can be expressed in the form:
If we multiply by 2, we obtain:
From this equation, we see that the integer part of , which must be either 0 or 1 because , is simply .
So we can say , where and where
To find , we repeat the process. At each step, the fractional part of the number from the previous step is multiplied by 2. The digit to the left of the decimal point in the product will be 0 or 1 and contributes to the binary representation, starting with the most significant digit. The fractional part of the product is used as the multiplicand in the next step.
Examples of Converting from Decimal Notation to Binary Notation for Integers
(a) 11 (Decimal notation)
11 / 2 = Quotient 5, Remainder 1
5 / 2 = Quotient 2, Remainder 1
2 / 2 = Quotient 1, Remainder 0
1 / 2 = Quotient 0, Remainder 1
(b) 21 (Decimal Notation)
21 / 2 = Quotient 10, Remainder 1
10 / 2 = Quotient 5, Remainder 0
5 / 2 = Quotient 2, Remainder 1
2 / 2 = Quotient 1, Remainder 0
1 / 2 = Quotient 0, Remainder 1
Examples of Converting from Decimal Notation to Binary Notation for Fractions
(a) 0.81 (approximately)
0.81 * 2 = 1.62, Integer Part 1
0.62 * 2 = 1.24, Integer Part 1
0.24 * 2 = 0.48, Integer Part 0
0.48 * 2 = 0.96, Integer Part 0
0.96 * 2 = 1.92, Integer Part 1
0.92 * 2 = 1.84, Integer Part 1
(b) 0.25 (exactly)
0.25 * 2 = 0.5, Integer Part 0
0.5 * 2 = 1.0, Integer Part 1
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:
0000 = 0, 0001 = 1, 0010 = 2, 0011 = 3
0100 = 4, 0101 = 5, 0110 = 6, 0111 = 7
1000 = 8, 1001 = 9, 1010 = A, 1011 = B
1100 = C, 1101 = D, 1110 = E, 1111 = F
Because 16 symbols are used, the notation is called hexadecimal, and the 16 symbols are the hexadecimal digits.
Table 2.3 Decimal, Binary, and Hexadecimal
Decimal (base 10) | Binary (base 2) | Hexadecimal (base 16) |
|---|---|---|
0 | 0000 | 0 |
1 | 0001 | 1 |
2 | 0010 | 2 |
3 | 0011 | 3 |
4 | 0100 | 4 |
5 | 0101 | 5 |
6 | 0110 | 6 |
7 | 0111 | 7 |
8 | 1000 | 8 |
9 | 1001 | 9 |
10 | 1010 | A |
11 | 1011 | B |
12 | 1100 | C |
13 | 1101 | D |
14 | 1110 | E |
15 | 1111 | F |
16 | 0001 0000 | 10 |
17 | 0001 0001 | 11 |
18 | 0001 0010 | 12 |
31 | 0001 1111 | 1F |
100 | 0110 0100 | 64 |
255 | 1111 1111 | FF |
256 | 0001 0000 0000 | 100 |
Reasons for Using Hexadecimal Notation
Not only used for representing integers but also as a concise notation for representing any sequence of binary digits.
Reasons:
It is more compact than binary notation.
In most computers, binary data occupy some multiple of 4 bits, and hence some multiple of a single hexadecimal digit.
It is extremely easy to convert between binary and hexadecimal notation.
Summary
The decimal system
Positional number systems
The binary system
Converting between binary and decimal
Integers
Fractions
Hexadecimal notation