Bits

You may be familiar with the saying “Computers speak in 1s and 0s”, but have you ever grappled with what that means? It’s amazing to think how much they are capable of doing with just two symbols.

In our counting system, we use 10 symbols:

In the binary system—the language of the computer—we only have two symbols: 0 and 1, which we call bits. We say that our counting system is base-10, or decimal, and the binary system is base-2. Base-2 number systems have a few interesting properties that make them suited for digital use. Among them, the fact that they are very easy to represent physically. For example, a light switch can be either on or off, which can be represented by or , respectively. This is the basis for binary logic.

But if, then, we only have two symbols, how are computers able of representing so much information? How are long strings of s and s converted into the letters and symbols we see on our screen?

Bytes

Let us consider one bit. It can either be on () or off (). What if we add another bit? We can now represent four different states:

First BitSecond BitDecimal Value

We can keep on adding bits, and the number of states we can represent grows exponentially. For example, with bits, we can represent states, with , states, 4 bits, states, and so on. With only bits, we can represent states. We call this a byte.

This pattern of powers of yields insight into how we can interpret (or, “read”) binary. Consider the byte string: 10110111.

For the more math-inclined reader, we can make this more formal. Let be a binary string of length , and let be the th bit of (read from right to left; i.e., is the rightmost bit, called the least significant bit since it has the least value ). Then we can convert to decimal as follows:

Signed and Unsigned Values

It is important that we make the distinction here between positive and negative values. In the binary system, we have the concept of signed and unsigned values. Recall that a byte has states. If we use all bits to represent a positive number (unsigned), we can represent values from to . However, if we wish to allow for negative values (signed), we can only represent values in the range to .

This changes the way we interpret the bits. For example, if we have the unsigned byte 11111111, we interpret it . If we considered it a signed byte, we would interpret it as . We won’t get into the nitty gritty of this here, but I’d encourage you to look up two's complement.