Computers store and operate on data represented in the binary number system. A great many aspects of computer science require some understanding of the binary number system. In order to understand the binary number system, it is often helpful to examine a number system we are all familiar with.
At some point in grammar school, you learned the “decimal” number system. Such a number system is based upon units of “10″. In mathematics and computer science we call the decimal number system the “Base 10″ number system. We use the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 to represent numbers in the following way:
Digits | Representation |
---|---|
0 | Value of 0 |
1 | Value of 1 |
2 | Value of 2 |
3 | Value of 3 |
4 | Value of 4 |
5 | Value of 5 |
6 | Value of 6 |
7 | Value of 7 |
8 | Value of 8 |
9 | Value of 9 |
10 | One “group” of 10 followed by the value of 0 |
11 | One “group” of 10 followed by the value of 1 |
… | … |
20 | Two “groups” of 10 followed by the value of 0 |
… | … |
100 | One “group” of 100 followed by zero groups of 10 followed by the value of 0 |
… | … |
125 | One “group” of 100 followed by 2 groups of 10 followed by the value of 5 |
In other words, when we work with the decimal (Base 10) number system, we tend to think in groups of 10, 100, 1000 and so on. We count up using the symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Each successive “place” in a number is a multiple of 10. That is, we have the “ones”. “tens”, “hundreds”, “thousands” and so on.
Number: 125 Hundreds Tens Ones 1 2 5 Number: 3461 Thousands Hundreds Tens Ones 3 4 6 1
In the binary (Base 2) number system, a digit can only take on one of two values: Either 0 or 1. We call such a digit a “bit” (short for “Binary Digit”). Each successive “bit” in a binary number is a multiple of 2. That is we have the “ones”, “twos”, “fours”, “eights”, “sixteens”, “thirtytwos” and so on. Below are some examples of binary numbers:
Decimal Digits | Binary Digits | Representation |
---|---|---|
0 | 0 | Value of 0 |
1 | 1 | Value of 1 |
2 | 10 | One “group” of 2 followed by the value 0 |
3 | 11 | One “group” of 2 followed by the value 1 |
4 | 100 | One “group” of 4 followed by 0 groups of 2 followed by the value 0 |
5 | 101 | One “group” of 4 followed by 0 groups of 2 followed by the value 1 |
6 | 110 | One “group” of 4 followed by 1 group of 2 followed by the value 0 |
7 | 111 | One “group” of 4 followed by 1 group of 2 followed by the value 1 |
8 | 1000 | One “group” of 8, 0 groups of 4, 0 groups of 2 and the value 0 |
… | … | … |
20 | 10100 | One “group” of 16, 0 groups of 8, 1 group of 4, 0 groups of 2 and the value 0 |
… | … | … |
100 | 1100100 | 1 group of 64, 1 group of 32, 0 groups of 16, 0 groups of 8, 1 group of 4, 0 groups of 2 and 0 |
… | … | … |
125 | 1111101 | 1 group of 64, 1 group of 32, 1 group of 16, 1 group of 8, 1 group of 4, 0 groups of 2 and 1 |
Computer scientists routinely memorize powers of 2. The process is simply to start with 0, 1 and then to double the number:
0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4098, 8192, 16384, 32768, 65536 and so on...
You may have notices that the RAM memory in your PC is also quite likely a power of 2:
8 Megabytes of RAM 16 Megabytes of RAM 32 Megabytes of RAM 64 Megabytes of RAM 128 Megabytes of RAM 256 Megabytes of RAM and so on
Some questions we commonly ask are:
- If I need to store the number 1 through 100, how many bits will I need?
We see that with 7 bits, we can represent numbers from 0 to 127. So 7 bits is all we would need to store numbers from 1 to 100. - What is the largest number I can represent using 16 bits?
The fastest way to calculate this is to take 2 to the 16th power (216) and then subtract 1.
2 16 = 65,536
So the largest number we can represent with 16 bits is: 65,536 – 1 = 65,535 - In my database, I can store 28 records in one disk block (a fixed sized storage area on the disk). How many bits would be required to index all of the records in one block?
One way to answer this is to just run up the powers of 2:
0, 1, 2, 4, 8, 16, 32, 64…
Since with 5 bits we can represent numbers from 0 to 31, (recall that 2 to the 5th power is 32), all we should need are 5 bits to index the 28 record entries in the block. - In networking, version 4 of the TCP/IP protocol designates IP addresses that are 32 bits long. How many hosts can be defined using 32 bits?
- Also in networking, the ethernet LAN protocol specifies that every ethernet device have a 48-bit Media Access Control (MAC) address.