If you've ever done any computer programming, then you've had extensive experience with the following subject. Even high-level programming touches on these concepts, although high-level languages shield us from the nuts and bolts of number systems as much as possible. If you're curious about alternative number systems as they apply to computer programming, read on. If you would rather be doing something else, this is your chance. Go!
Now that we've cleared out the disinterested, let's get on with it. The history of numbering systems is a long one. From the ancient Babylonians (who used a Base-60 numbering system written in cuneiform) to modern computing (programming, encoding, and encryption), numbering systems have been the basis, the backbone of technology. From the lowest-level bit to 64-bit values and beyond, these numbering systems are vital to the way humanity experiences the world. Even the pixel patterns that make up the words you're reading are dependent on whether or not a bit is equal to one or zero. With that in mind, let's get started.
In terms of programming, alternative number systems were originally used, and indeed they are still used, to conserve valuable memory space and to reduce lengthy clock cycles. In the following table, BIN represents the BINARY or BASE 2 number system, HEX represents the HEXADECIMAL or BASE 16 number system, and DEC represents the DECIMAL or BASE 10.
BIN DEC HEX | BIN DEC HEX
--------------------|--------------------
0000 = 0 = 0 | 1000 = 8 = 8
0001 = 1 = 1 | 1001 = 9 = 9
0010 = 2 = 2 | 1010 = 10 = A
0011 = 3 = 3 | 1011 = 11 = B
0100 = 4 = 4 | 1100 = 12 = C
0101 = 5 = 5 | 1101 = 13 = D
0110 = 6 = 6 | 1110 = 14 = E
0111 = 7 = 7 | 1111 = 15 = F
After viewing this table, the advantages of the hexadecimal numbering system become clear. Sixteen different values may be represented by a single digit.
In the BINARY or BASE 2 number system, each added digit can represent an exponentially larger possibility of values. This means that for every digit used in binary, the possible decimal values represented increases by a factor of 2. Just one binary digit, or BIT, can represent two decimal values, 0 or 1. Add another binary digit, and the number can represent four decimal values, from 0 to 3. Add another binary digit, and the number can represent eight decimal values, from 0 to 7.
In the HEXADECIMAL or BASE 16 number system, each additional digit increases the possible values represented by a factor of sixteen. A single hexadecimal digit can represent sixteen decimal values, from 0 to 15. Adding another hex digit increases the number of possible represented values by a factor of 16, so that the possible values now range from 0 to 255. You get the idea.
This translates into an exponential increase in storage capacity and an exponential decrease in processing time. Are you beginning to see the value of these alternative number systems (pun intended)? Now that we've answered the WHY, let's move on to the HOW.
The BIT
A bit is the smallest piece of data that exists. A bit is one-eigth of a byte (see below), and can equal either a one (1) or a zero (0). If you're wondering how ones and zeros apply to computing, think of each one and each zero as a digital instruction where one equals ON and zero equals OFF. In the programming world, a bit is said to be on or off depending on whether it equals one or zero. These ones and zeros make up the BINARY or BASE 2 number system. For example:
0000 = 0 0100 = 4 1000 = 8 1100 = 12
0001 = 1 0101 = 5 1001 = 9 1101 = 13
0010 = 2 0110 = 6 1010 = 10 1110 = 14
0011 = 3 0111 = 7 1011 = 11 1111 = 15
The NIBBLE
A nibble is made up of four bits, and is one-half of a byte (see below). A nibble has a minimum value of 0000 and a maximum value of 1111 (min 0 and max 15 in the decimal number system). The astute among you will have noticed that a nibble can contain 16 different values (0 to 15), which happen to be the basis for our next number system, the HEXADECIMAL or BASE 16 number system. Hexadecimal numbers are created using the following digits:
0 1 2 3 4 5 6 7 8 9 A B C D E F
The BYTE
A byte is (most commonly, and for the purposes of this blog) made up of eight bits, or two nibbles. The byte is the basic unit of information storage in computer science. A byte can store 256 different values, from a minimum of 00000000 (DEC 0 or HEX 00) to a maximum of 11111111 (DEC 255 or HEX FF). This will be important in a moment.
Okay, let's put it all together in familiar computer terms. You've probably noticed that numbers are thrown around a lot when discussing a computer's capabilities. For example, you may hear that a particular computer has a certain number of megabytes of random access memory (RAM), or you might hear that the same computer has a hard drive capable of storing a certain number of gigabytes of information. All of these numbers you hear are based on the byte, and all are multiples of 8. Now, I know what you're thinking, what about kilobytes and megabytes? Those aren't multiples of 8, right? In the computer world, they are.
In mathematics, the prefixes kilo, mega, giga, tera, and so on, represent exponentally increasing values, but these prefixes are traditionally based on the decimal or base 10 system, so that kilo means thousand, mega means million, giga means billion, tera means trillion, etc. But in the computer world, numbers are based on the binary or base 2 system, so when you hear the terms kilobyte (KB), megabyte (MB), gigabyte (TB), and terabyte (TB), they do not translate exactly. A kilobyte is not equal to 1000 bytes because 1000 is an exponent of 10, or 103. A kilobyte is an exponent of 2, and is therefore equal to decimal 1024, or 210. So a kilobyte is equal to 1024 bytes, not 1000 bytes.
Now that we (hopefully) understand these alternative numbering systems, let's talk about how they are used in computing. Imagine that I've asked you to use four adjectives to describe someone you know. For the purposes of this demonstration, let's limit the adjectives to: funny, hairy, jolly, and witty. (On a tangent, if you're wondering what Freud would say about my choice of adjectives, you're reading the wrong blog.)
Now, you could use any combination of those four adjectives to describe this person. Now, imagine that you had to use these four adjectives to describe not just this person, but everyone you know and everyone you don't know. Let's further imagine that you are not looking forward to this task, and you're desperately trying to think of some way to shorten the amount of work this is going to take. So you create a checklist with four boxes.
o funny
o hairy
o jolly
o witty
Then you copy this checklist one time for each person in the world. Now, instead of keeping track of a set of descriptions for each and every person, you merely have to keep track of each person's checklist. If a person, let's call him Hilarius Hairybottomus, is funny and hairy but not jolly or witty, his checklist would look like this:
• funny
• hairy
o jolly
o witty
Okay, this is easier, but the system can still be improved. If we used a digit to represent each adjective in order, then we could further simplify this task. We would need four digits, one for each word, and we could arrange them in the same order as the adjectives to avoid confusion. So the first digit would represent funny, the second would represent hairy, and so on. Using this system, the following series of four digits could be used to represent the characteristics of Hilarius Hairybottomus:
1100
If, on the other hand, our friend Mr. Hairybottomus paid for electrolysis and at the same time read a few books to increase his wit, we could easily change this four digit number to effectively represent his new characteristics:
1001
I bet you're wondering how this applies to computer science, eh? Imagine that instead of a person, Mr. Hairybottomus is a piece of computer data. He's sitting right there next to all the other thousands of data on your hard drive. This data has certain attributes that indicate how it should be treated by the computer's software, attributes like Readonly, Hidden, System, Volume, Directory, File, Archive, and Encrypted. Rather than storing these attributes for each and every single piece of data, why not store a number that represents all of them? This is where binary numbers come in. Each digit, or bit, in the following number is used to indicate whether or not the data has a specific attribute. In this example, a one means that the attribute applies to the data, and a zero means that the attribute does not apply:
Bits: 7 6 5 4 3 2 1 0 Attribute
----------------------------------
. . . . . . . 1 Readonly
. . . . . . 1 . Hidden
. . . . . 0 . . System
. . . . 0 . . . Volume
. . . 0 . . . . Directory
. . 1 . . . . . File
. 1 . . . . . . Archive
1 . . . . . . . Encrypted
As in the table above, instead of storing lengthy descriptions of data, we can simply represent the presence or absence of each attribute with a single byte:
11100011 (Hilarius Hairybottomus data attributes)
If we want to further simplify this, we can substitute the binary representation for the hexadecimal representation. Instead of the eight digit binary number, we need only a two digit hexadecimal number:
E3 (Hilarius Hairybottomus data attributes)
This is just one example of the many ways that the complexities of alternative number systems are used to simplify the computing world. Don't you just love the smell of irony in the morning?