Java Reference

In-Depth Information

Memory

There are generally two kinds of memory. ROM, or
read-only memory
, con-

tains data that can only be read. For example, the set of instructions that the com-

puter executes when it starts up, or
boots
, is in ROM. RAM, or
random-access

memory
, can be written as well as read. Memory is physically designed to pro-

vide extremely fast access to it, while access to a hard disk is much slower. Fast

access to RAM is important because the CPU is constantly reading and writing

RAM as it executes instructions. Because electricity maintains the data in RAM,

the contents of RAM is destroyed when the computer is turned off.

Computers store information, such as words, numbers, sounds, and pictures,

as a series of 1s and 0s, or
bits
(
binary digits
) because it is physically easy to

build devices that represent 1 or 0. A device is on or off, is magnetized or not,

has current running through it or not, allows light through it or not, and so on.

Humans normally write integers in the
decimal
number system. We have ten

digits at our disposal, and we count like this: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. After all

ten digits are used up we need two digits to keep counting, and ten is written as

a 1 followed by a 0: 10. Similarly, after 99 comes 100.

In computer memory, integers (and all other data) are stored using the
bina-

ry
number system, in which only two digits are used: 0 and 1. Counting in bina-

ry follows the same algorithm as in the decimal number system, but with fewer

digits. First, we count through all the digits: 0, 1. Because there are no more dig-

its, the next number, two, is represented by 10. So the decimal number 2 is the

same as the binary number 10. They are just different representations of what we

call “two”. In the binary system, after 10 comes 11, and then 100 (“four”).

0

0

0

0

1

1

1

1

2
0

2

2

2

10

2
1

3

3

3

11

4

4

4

100

2
2

5

5

5

101

6

6

6

110

7

7

7

111

8

10

8

1000

2
3

9

11

9

1001

10

12

A

1010

11

13

B

1011

16

20

10

10000

2
4

20

24

14

10100

64

80

40

1000000

2
6

decimal

octal

hexadecimal

binary

power of 2

Figure 0.2:
Decimal, octal, hexadecimal, and binary numbers

Search WWH ::

Custom Search