Java Reference
InDepth Information
Fig. 0.2 shows some integer values in the decimal system; the
octal
system,
which uses eight digits; the
hexadecimal
system, which uses sixteen digits (0 ..
9, A .. F); and the binary system. As can be seen, the decimal integer 20 is writ
ten as 24 in octal, 14 in hexadecimal, and 10100 in binary. You will encounter
hexadecimal numbers during your programming career and occasionally see
octal numbers. A
hex dump
, for example, is a lowlevel printout of computer
memory. Because 16 is a power of 2, binary numbers can be translated easily into
hexadecimal, which is easier to read and interpret than binary.
Computer memory consists of a sequence of
bytes
, each of which consists
of eight bits. As shown in Fig. 0.3, the first byte is numbered 0, the second 1, the
third 2, and so on. This number is called the
address
of the byte, and bytes are
often called
memory locations
.
Early computers had at most a few thousand bytes, and memory was expen
sive, on the order of a penny a bit. A megabyte is 2
20
= 1,048,576 bytes, so at
the 1950 price of a penny a bit, 512 megabytes of RAM would cost over
$83,000! A gigabyte is 1024 megabytes. These days, 512 megabytes (“half a
gig”) of RAM, which costs only a few hundred dollars, is considered a good
amount of RAM in a new computer. But in three years, it will probably not be
enough to run the latest operating systems and applications well, especially the
latest 3D immersive games and complex movie and photo editing software.
Because there are only eight bits in a byte, the largest integer that can be put
in a byte is 11111111, or 2
8

1 = 255. To deal with larger integers, several con
tiguous bytes are used. For example, suppose we use four bytes to store an inte
ger; that is 32 bits. Since the sign of an integer has to be represented too, the
range of integers that can be stored in the four bytes is 2
31
..2
31
1.
Figure 0.4 describes some basic facts about binary numbers.
Storage devices
Most desktop and laptop computers come with an internal hard disk, and it
is easy to attach external hard disks for extra storage, backup storage, and mobile
storage —floppy disks (which are becoming extinct), zip drives, memory sticks,
and so forth. A pretty good desktop at the time of this writing comes with an 80
gigabyte hard drive, 512 megabytes of memory, and any number of other exter
nal drives, depending on the buyer's choice. This is quite in contrast to the early
byte 0
10100101
byte 1
01001000
byte 2
11111111
byte 3
00000001
.
.
.
.
.
.
Figure 0.3:
Bytes in memory
1. A binary number that consists of a 1 followed by 0s
is a power of two. For example, binary 10000 = 2
4
= sixteen.
2. A binary number that consists entirely of 1s is 1
less than a power of two. For example, binary 111
= 2
3

1 = seven.
3
. To double the value of a binary number, append a
0. For example, 1010 is ten, and 10100 is twenty.
Figure 0.4:
Binary number tidbits
Search WWH ::
Custom Search