In this appendix, we introduce the key number systems that programmers use, especially when they are working on software projects that require close interaction with machinelevel hardware. Projects like this include operating systems, computer networking software, compilers, database systems and applications requiring high performance.
When we write an integer such as 227 or 63 in a program, the number is assumed to be in the decimal (base 10) number system. The digits in the decimal number system are 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9. The lowest digit is 0 and the highest digit is 9one less than the base of 10. Internally, computers use the binary (base 2) number system. The binary number system has only two digits, namely 0 and 1. Its lowest digit is 0 and its highest digit is 1one less than the base of 2.
As we will see, binary numbers tend to be much longer than their decimal equivalents. Programmers who work in assembly languages and in high-level languages like C# that enable programmers to reach down to the machine level, find it cumbersome to work with binary numbers. So two other number systemsthe octal number system (base 8) and the hexadecimal number system (base 16)are popular primarily because they make it convenient to abbreviate binary numbers.
In the octal number system, the digits range from 0 to 7. Because both the binary number system and the octal number system have fewer digits than the decimal number system, their digits are the same as the corresponding digits in decimal.
The hexadecimal number system poses a problem because it requires 16 digitsa lowest digit of 0 and a highest digit with a value equivalent to decimal 15 (one less than the base of 16). By convention, we use the letters A through F to represent the hexadecimal digits corresponding to decimal values 10 through 15. Thus in hexadecimal we can have numbers like 876 consisting solely of decimal-like digits, numbers like 8A55F consisting of digits and letters and numbers like FFE consisting solely of letters. Occasionally, a hexadecimal number spells a common word such as FACE or FEEDthis can appear strange to programmers accustomed to working with numbers. The digits of the binary, octal, decimal and hexadecimal number systems are summarized in Fig. B.1Fig. B.2.
Binary digit |
Octal digit |
Decimal digit |
Hexadecimal digit |
---|---|---|---|
0 |
0 |
0 |
0 |
1 |
1 |
1 |
1 |
2 |
2 |
2 |
|
3 |
3 |
3 |
|
4 |
4 |
4 |
|
5 |
5 |
5 |
|
6 |
6 |
6 |
|
7 |
7 |
7 |
|
8 |
8 |
||
9 |
9 |
||
A (decimal value of 10) |
|||
B (decimal value of 11) |
|||
C (decimal value of 12) |
|||
D (decimal value of 13) |
|||
E (decimal value of 14) |
|||
F (decimal value of 15) |
Attribute |
Binary |
Octal |
Decimal |
Hexadecimal |
---|---|---|---|---|
Base |
2 |
8 |
10 |
16 |
Lowest digit |
0 |
0 |
0 |
0 |
Highest digit |
1 |
7 |
9 |
F |
Each of these number systems uses positional notationeach position in which a digit is written has a different positional value. For example, in the decimal number 937 (the 9, the 3 and the 7 are referred to as symbol values), we say that the 7 is written in the ones position, the 3 is written in the tens position and the 9 is written in the hundreds position. Note that each of these positions is a power of the base (base 10) and that these powers begin at 0 and increase by 1 as we move left in the number (Fig. B.3).
Positional values in the decimal number system |
|||
---|---|---|---|
Decimal digit |
9 |
3 |
7 |
Position name |
Hundreds |
Tens |
Ones |
Positional value |
100 |
10 |
1 |
Positional value as a power of the base (10) |
102 |
101 |
100 |
For longer decimal numbers, the next positions to the left would be the thousands position (10 to the 3rd power), the ten-thousands position (10 to the 4th power), the hundred-thousands position (10 to the 5th power), the millions position (10 to the 6th power), the ten-millions position (10 to the 7th power) and so on.
In the binary number 101, the rightmost 1 is written in the ones position, the 0 is written in the twos position and the leftmost 1 is written in the fours position. Each position is a power of the base (base 2) and that these powers begin at 0 and increase by 1 as we move left in the number (Fig. B.4). So, 101 = 1 * 22 + 0 * 21 + 1 * 20 = 4 + 0 + 1 = 5.
Positional values in the binary number system |
|||
---|---|---|---|
Binary digit |
1 |
0 |
1 |
Position name |
Fours |
Twos |
Ones |
Positional value |
4 |
2 |
1 |
Positional value as a power of the base (2) |
22 |
21 |
20 |
For longer binary numbers, the next positions to the left would be the eights position (2 to the 3rd power), the sixteens position (2 to the 4th power), the thirty-twos position (2 to the 5th power), the sixty-fours position (2 to the 6th power) and so on.
In the octal number 425, we say that the 5 is written in the ones position, the 2 is written in the eights position and the 4 is written in the sixty-fours position. Note that each of these positions is a power of the base (base 8) and that these powers begin at 0 and increase by 1 as we move left in the number (Fig. B.5).
Positional values in the octal number system |
|||
---|---|---|---|
Decimal digit |
4 |
2 |
5 |
Position name |
Sixty-fours |
Eights |
Ones |
Positional value |
64 |
8 |
1 |
Positional value as a power of the base (8) |
82 |
81 |
80 |
For longer octal numbers, the next positions to the left would be the five-hundred-and-twelves position (8 to the 3rd power), the four-thousand-and-ninety-sixes position (8 to the 4th power), the thirty-two-thousand-seven-hundred-and-sixty-eights position (8 to the 5th power) and so on.
In the hexadecimal number 3DA, we say that the A is written in the ones position, the D is written in the sixteens position and the 3 is written in the two-hundred-and-fifty-sixes position. Note that each of these positions is a power of the base (base 16) and that these powers begin at 0 and increase by 1 as we move left in the number (Fig. B.6).
Positional values in the hexadecimal number system |
|||
---|---|---|---|
Decimal digit |
3 |
D |
A |
Position name |
Two-hundred-and-fifty-sixes |
Sixteens |
Ones |
Positional value |
256 |
16 |
1 |
Positional value as a power of the base (16) |
162 |
161 |
160 |
For longer hexadecimal numbers, the next positions to the left would be the four-thousand-and-ninety-sixes position (16 to the 3rd power), the sixty-five-thousand-five-hundred-and-thirty-sixes position (16 to the 4th power) and so on.
B 2 Abbreviating Binary Numbers as Octal and Hexadecimal Numbers |
Preface
Index
Introduction to Computers, the Internet and Visual C#
Introduction to the Visual C# 2005 Express Edition IDE
Introduction to C# Applications
Introduction to Classes and Objects
Control Statements: Part 1
Control Statements: Part 2
Methods: A Deeper Look
Arrays
Classes and Objects: A Deeper Look
Object-Oriented Programming: Inheritance
Polymorphism, Interfaces & Operator Overloading
Exception Handling
Graphical User Interface Concepts: Part 1
Graphical User Interface Concepts: Part 2
Multithreading
Strings, Characters and Regular Expressions
Graphics and Multimedia
Files and Streams
Extensible Markup Language (XML)
Database, SQL and ADO.NET
ASP.NET 2.0, Web Forms and Web Controls
Web Services
Networking: Streams-Based Sockets and Datagrams
Searching and Sorting
Data Structures
Generics
Collections
Appendix A. Operator Precedence Chart
Appendix B. Number Systems
Appendix C. Using the Visual Studio 2005 Debugger
Appendix D. ASCII Character Set
Appendix E. Unicode®
Appendix F. Introduction to XHTML: Part 1
Appendix G. Introduction to XHTML: Part 2
Appendix H. HTML/XHTML Special Characters
Appendix I. HTML/XHTML Colors
Appendix J. ATM Case Study Code
Appendix K. UML 2: Additional Diagram Types
Appendix L. Simple Types
Index