Data Types  «Prev  Next»
 Lesson 2 Binary numbers Objective Explain what a binary number is.

## Binary Numbers in Computer Science

The number system that you are probably most familiar with is the decimal, or base 10, number system. When representing a number using decimal notation, each position in the number corresponds to a power of 10, and each digit of the number can be one of the numerals 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9. For example, the decimal number 6437 represents the sum:
```6 * 103 + 4 * 102 + 3 * 101 + 7 * 100
```
or
```6 * 1000 + 4 * 100 + 3 * 10 + 7 * 1
```

Because computers store data as a sequence of switches that can be either on or off, they use a base 2 number system referred to as the binary number system. In this number system, each position in a number corresponds to a power of 2, and each digit can be either the binary digit 1 or 0. For example, the binary number 110101 represents the following sum, which is equal to 45 in the decimal number system:
1 * 25 + 1 * 24 + 0 * 23 + 1 * 22 + 0 * 21 + 1 * 20 or
1 * 32 + 1 * 16 + 0 * 8 + 1 * 4 + 0 * 2 + 1 * 1
1. Decimal number system: Base 10 number system.
2. Binary number system: Base 2 number system.
Here's a table showing the 8-bit binary numbers and their decimal equivalents.

Binary Decimal
```00000000 00000001 00000010 00000011 00000100 . . . 11111101 11111110 11111111``` ```  0   1   2   3   4   .   .   . 253 254 255```

Note that with 8 bits you can represent 28 or 256 numbers. With n bits you can represent 2n numbers. Now that you know how to interpret binary numbers, you are ready to proceed to the next lesson, where you will learn how to convert between binary and decimal form.

The expression "binary digit" meaning a 1 or a 0 is usually referred to as a bit. Figure A-2 shows the decimal number 2001 expressed in binary, octal, decimal, and hexadecimal form. The number 7B9 is obviously hexadecimal, because the symbol B can only occur in hexadecimal numbers. However, the number 111 might be in any of the four number systems discussed. To avoid ambiguity, people use a subscript of 2, 8, 10, or 16 to indicate the radix when it is not obvious from the context.

As an example of binary, octal, decimal, and hexadecimal notation, consider Fig. Figure 3-2.2 , which shows a collection of nonnegative integers expressed in each of these four different systems. Perhaps some archaeologist thousands of years from now will discover this table and regard it as the Rosetta Stone to late twentieth century and early twenty-first century number systems.