Memory: Not Exactly 0s and 1s


No doubt you've heard that computers only process 0s and 1s. This can't possibly be true. Computers are used to count votes in elections, so they must be capable of counting past 1. Computers are also used to model the behavior of subatomic particles whose masses are tiny fractions, so they must be capable of processing fractions as well as whole numbers. They're used for writing documents, so they must be capable of processing text as well as numbers.

On the most fundamental level, computers do not process 0s and 1s, or whole numbers, or fractions, or text. Computers are electronic circuits, so all they really process is electricity. Computer components are designed so that their internal voltages are either approximately zero or approximately 5 or 6 volts. When part of a computer circuit carries a voltage of 5 or 6 volts, we say that it has a value of 1. When part of a circuit carries zero voltage, we say that it has a value of 0. (Fortunately, this is all the electronics knowledge you need to become a master programmer.)

It's all a matter of interpretation. Voltages are interpreted as 0s and 1s. As you'll see later in this chapter and in Chapter 2, "Data," the 0s and 1s are organized into clusters that are interpreted as numbers. More sophisticated parts of the computer interpret those numbers as codes that represent fractions, or text, or colors, or images, or any of the other myriad classes of objects that can be represented in a computer.

A modern computer contains billions of microscopic components, each of which has a value of 0 or 1. Any circuit where we only care about the approximate values of the voltages is known as a digital circuit. Computers that are made of digital circuitry are known as digital computers.

Note

The opposite of digital is analog. In an analog circuit, we care about the exact voltages of the components. Analog circuits are ideal for certain applications, such as radios and microwave ovens, but they don't work so well for computers. Analog computers were used in the 1940s, but they were an evolutionary dead end. All modern computers are digital.

One simple but useful type of digital circuit is known as memory. A memory circuit just stores a digital value (0 or 1, because we programmers don't have to think about voltages). A single unit of memory is called a bit, which is an abbreviation for "binary digit." You can think of a bit as a microscopic box, the contents of which are available to the rest of the computer. From time to time the computer might change the contents. Bits are usually drawn as shown in Figure 1.1.


Figure 1.1: A bit

Bits are usually organized in groups of eight, known as bytes. Figure 1.2 shows a byte that contains an arbitrary combination of 0s and 1s.

click to expand
Figure 1.2: A byte

Note that the individual bits are numbered from right to left, and that the numbering starts from 0. Computer designers always start numbering things from 0 rather than 1. This is true whether they are numbering bits in a byte, bytes in memory (as we are about to see), or components in an array (as we will see in Chapter 6).

A byte can contain 256 combinations of bit values: 2 possibilities for bit #0 times 2 possibilities for bit #1 times 2 possibilities for bit #3, and so on up through bit #7.

If you looked at a computer through a microscope and saw the byte shown in Figure 1.2, you might wonder what value it contained. You would see the 0s and 1s, but what would they mean? It's a great question that has no good answer. A byte might represent an integral number, a fraction, part of an integer or fraction, a character in a document, a color in a picture, or an instruction in a program. It all depends on the byte's context. As a programmer, you are the one who dictates how each byte will be interpreted.




Ground-Up Java
Ground-Up Java
ISBN: 0782141900
EAN: 2147483647
Year: 2005
Pages: 157
Authors: Philip Heller

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