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

Binary Numbers in Computer Science

In the realm of computer science, a binary number is a value expressed in the binary numeral system, a method for representing numbers using only two different symbols: typically '0' (zero) and '1' (one). Binary numbers form the cornerstone of all data representation in digital computers, due to their direct compatibility with electronic circuitry, which operates on two distinct states: on (1) and off (0).

1) Storing Numbers:

When storing numerical values, a digital computer leverages binary numbers to encode the information. Each digit within a binary number is referred to as a bit, the smallest unit of data in a computer. Multiple bits are combined to form larger units such as bytes (commonly 8 bits), kilobytes, megabytes, and so on. For example, the decimal number 5 is represented in binary as 101. This is calculated as (1 × 2^2) + (0 × 2^1) + (1 × 2^0), which equates to 4 + 0 + 1. The computer's memory stores this binary representation using transistors that are set to on or off states, corresponding to 1s and 0s, respectively. Integers are typically stored in a fixed amount of space, such as 32 or 64 bits, with one bit sometimes used to represent the sign for signed numbers (positive or negative). Floating-point numbers, used to represent decimals and scientific notations, have a more complex binary representation that divides the bits between a sign, exponent, and fraction, following standards such as IEEE 754.

2) Storing Text:

For text storage, computers translate characters, such as letters, numbers, and symbols, into binary numbers using character encoding schemes. The most basic form of encoding is the American Standard Code for Information Interchange (ASCII), where each character is assigned a unique 7-bit binary number. For example, the capital letter 'A' is represented by the binary number 1000001 in ASCII. More comprehensive encoding systems, like Unicode, use a variable number of bytes to accommodate a vast array of characters from multiple languages and symbols, supporting global communication and information exchange. A Unicode transformation format, such as UTF-8, represents each character with a unique binary sequence, which can vary in length to optimize storage space for common characters. In both numbers and text representation, the binary system underlies the functioning of digital computers, enabling them to perform a wide range of operations by manipulating binary digits through their hardware circuits. This system of representation is efficient, reliable, and universally adopted in the design of computer architectures and digital communication systems.
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

What can be represented with 8 bits?

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.

Figure 3-2.1:  The number 2001 in binary, octal, and hexadecimal
Figure 3-2.1: The number 2001 in binary, octal, and hexadecimal.

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.
Figure 3-2.2: Decimal numbers and their binary, octal, and hexadecimal equivalents.
Figure 3-2.2: Decimal numbers and their binary, octal, and hexadecimal equivalents.