Section B.1. Introduction


B.1. Introduction

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 machine-level 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 0and 1. Its lowest digit is 0 and its highest digit is 1one less than the base of 2.

As you will see, binary numbers tend to be much longer than their decimal equivalents. Programmers who work in assembly languages and in high-level languages 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, the letters A through F represent the hexadecimal digits corresponding to decimal values 10 through 15. Thus, in hexadecimal, you 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 Figs. B.1 and B.2.

Figure B.1. Digits of the binary, octal, decimal and hexadecimal number systems.

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 (decimalvalue of 10)

   

B (decimalvalue of 11)

   

C (decimalvalue of 12)

   

D (decimalvalue of 13)

   

E (decimalvalue of 14)

   

F (decimalvalue of 15)


Figure B.2. Comparing the binary, octal, decimal and hexadecimal number systems.

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).

Figure B.3. Positional values in the decimal number system.

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 right most 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.

Figure B.4. Positional values in the binary number system.

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).

Figure B.5. Positional values in the octal number system.

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

82

81

80

power of the base (8)

   


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).

Figure B.6. Positional values in the hexadecimal number system.

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.



Visual BasicR 2005 for Programmers. DeitelR Developer Series
Visual Basic 2005 for Programmers (2nd Edition)
ISBN: 013225140X
EAN: 2147483647
Year: 2004
Pages: 435

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net