Java Reference
In-Depth Information
A PPENDIX F
Number Systems
F.1 Introduction
Computers use binary numbers internally, because computers are made naturally to store and
process 0s and 1s. The binary number system has two digits, 0 and 1. A number or character
is stored as a sequence of 0s and 1s. Each 0 or 1 is called a bit (binary digit).
In our daily life we use decimal numbers. When we write a number such as 20 in a pro-
gram, it is assumed to be a decimal number. Internally, computer software is used to convert
decimal numbers into binary numbers, and vice versa.
We write computer programs using decimal numbers. However, to deal with an operating
system, we need to reach down to the “machine level” by using binary numbers. Binary num-
bers tend to be very long and cumbersome. Often hexadecimal numbers are used to abbreviate
them, with each hexadecimal digit representing four binary digits. The hexadecimal number
system has 16 digits: 0-9 and A-F. The letters A, B, C, D, E, and F correspond to the decimal
numbers 10, 11, 12, 13, 14, and 15.
The digits in the decimal number system are 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. A decimal
number is represented by a sequence of one or more of these digits. The value that each digit
represents depends on its position, which denotes an integral power of 10. For example, the
digits 7, 4, 2, and 3 in decimal number 7423 represent 7000, 400, 20, and 3, respectively, as
shown below:
binary numbers
decimal numbers
hexadecimal number
= 7
10 3
10 2
10 1
10 0
*
+
*
+
*
+
*
7
4
2
3
4
2
3
10 3
10 2
10 1
10 0
=
7000
+
400
+
20
+
3
=
7423
The decimal number system has ten digits, and the position values are integral powers of 10.
We say that 10 is the base or radix of the decimal number system. Similarly, since the binary
number system has two digits, its base is 2, and since the hex number system has 16 digits,
its base is 16.
If 1101 is a binary number, the digits 1, 1, 0, and 1 represent 1
base
radix
2 3 ,1
2 2 ,0
2 1 , and
*
*
*
2 0 , respectively:
1
*
= 1
2 3
2 2
2 1
2 0
1
1
0
1
*
+
1
*
+
0
*
+
1
*
2 3
2 2
2 1
2 0
=
8
+
4
+
0
+
1
=
13
16 3 ,4
16 2 ,2
16 1 , and
If 7423 is a hex number, the digits 7, 4, 2, and 3 represent 7
*
*
*
16 0 , respectively:
3
*
= 7
16 3
16 2
16 1
16 0
7
4
2
3
*
+
4
*
+
2
*
+
3
*
16 3
16 2
16 1
16 0
=
28672
+
1024
+
32
+
3
=
29731
1273
 
 
 
 
Search WWH ::




Custom Search