Encyclopedia  |   World Factbook  |   World Flags  |   Reference Tables  |   List of Lists     
   Academic Disciplines  |   Historical Timeline  |   Themed Timelines  |   Biographies  |   How-Tos     
Sponsor by The Tattoo Collection
Binary numeral system
Main Page | See live article | Alphabetical index

Binary numeral system

The binary or base-two numeral system is a system for representing numbers in which a radix of two is used; that is, each digit in a binary numeral may have either of two different values. Typically, the symbols 0 and 1 are used to represent binary numbers. Owing to its relatively straightforward implementation in electronic circuitry, the binary system is used internally by virtually all modern computers.

In contrast to the binary system, the commonly-used decimal numeral system has a radix of ten and uses the symbols 0 through 9. In the binary system, all numbers larger than one require more digits to write than they would in the decimal system. The number two is written "10" in binary; the number six requires three digits in binary, "110"; and the number nine-hundred ninety-nine (decimal "999") requires ten digits in binary, "1111100111". This extra length makes binary somewhat cumbersome for humans, so those who frequently work with binary numerals may use octal and hexadecimal notation as a form of shorthand.

Table of contents
1 History
2 Representation
3 Counting in binary
4 Binary arithmetic
5 Bitwise logical operations
6 Conversion to and from other numeral systems
7 Representing real numbers
8 See also
9 External link

History

The first known description of a binary numeral system was made by Pingala in his Chhandah-shastra, placed variously in the 5th century BC or the 2nd century BC. Pingala described the binary numeral system in connection with the listing of Vedic meters with short or long syllables. According to one Indian tradition, Pingala was the younger brother of the great grammarian Panini. The modern binary number system was first documented by Gottfried Leibniz. Pingala's system begins with the value one, while Leibniz' begins with zero; the modern binary numeral system begins with zero.

In 1854, British mathematician George Boole published a landmark paper detailing a system of logic that would become known as Boolean algebra. His logical system proved instrumental in the development of the binary system, particularly in its implementation in electronic circuitry.

Representation

A binary number can be represented by any sequence of bits (binary digits), which in turn may be represented by any mechanism capable of being in two mutually exclusive states. The following sequences of symbols could all be interpreted as binary numbers representing different values:

11010011
on off off on off on
- | - | | - | - - | - |
o x o o x o o x
N Y N N Y N Y Y Y

The numeric value represented in each case is dependent upon the value assigned to each symbol. In a computer, the numeric values may be represented by two different voltages; on a magnetic disk, magnetic polarities may be used. A "positive", "yes", or "on" state is not necessarily equivalent to the numerical value of one; it depends on the architecture in use.

In keeping with customary representation of numerals using arabic numerals, binary numbers are commonly written using the symbols 0 and 1. When written, binary numerals are often subscripted or suffixed in order to indicate their base, or radix. The following notations are equivalent:

100101 binary (explicit statement of format)
100101b (a suffix indicating binary format)
1001012 (a subscript indicating base-2 notation)

When spoken, binary numerals are usually pronounced by pronouncing each individual digit, in order to distinguish them from decimal numbers. For example, the binary numeral "100" is pronounced "one zero zero", rather than "one hundred", in order to make explicit the fact that a binary numeral is being discussed, as well as for purposes of correctness. Since the binary numeral "100" is equal to the decimal value four, it would be confusing, and numerically incorrect, to refer to the numeral as "one hundred."

Counting in binary

Counting in binary is similar to counting in any other number system. Beginning with a single digit, counting proceeds through each symbol, in increasing order. Decimal counting uses the symbols 0 through 9, while binary only uses the symbols 0 and 1.

When the symbols for the first digit are exhausted, the next-higher digit (to the left) is incremented, and counting starts over at 0. In decimal, counting proceeds like so:

00, 01, 02, ... 07, 08, 09 (rightmost digit starts over, and the 0 is incremented)
10, 11, 12, ... 17, 18, 19 (rightmost digit starts over, and the 1 is incremented)
20, 21, 22, ...

When the rightmost digit reaches 9, counting returns to 0, and the second digit is incremented. In binary, counting is similar, with the exception that only the two symbols 0 and 1 are used. When 1 is reached, counting begins at 0 again, with the digit to the left being incremented:

000, 001 (rightmost digit starts over, and the second 0 is incremented)
010, 011 (middle and rightmost digits start over, and the first 0 is incremented)
100, 101 (rightmost digit starts over again, middle 0 is incremented)
110, 111...

It has been said that "there are only 10 types of people in the world: those who understand binary, and those who don't."

Binary arithmetic

Arithmetic in binary is much like arithmetic in other numeral systems. Addition, subtraction, multiplication, and division can be performed on binary numerals.

Addition

The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple:

0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 10 (the 1 is carried)

Adding two "1" values produces the value "10", equivalent to the decimal value 2. This is similar to what happens in decimal when certain single-digit numbers are added together; if the result exceeds the value of the radix (10), the digit to the left is incremented:

5 + 5 = 10
7 + 9 = 16

This is known as carrying in most numeral systems. When the result of an addition exceeds the value of the radix, the procedure is to "carry the one" to the left and add the next place value. Carrying works the same way in binary:

    1 1 1 1     (carry)
    0 1 1 0 1
+   1 0 1 1 1
-------------
= 1 0 0 1 0 0

Starting in the rightmost column, 1 + 1 = 10. The 1 is carried to the left, and the 0 is written at the bottom of the rightmost column. The second column from the right is added: 1 + 0 + 1 = 10 again; the 1 is carried, and 0 is written at the bottom. The third column: 1 + 1 + 1 = 11. This time, a 1 is carried, and a 1 is written in the bottom row. Proceeding like this gives the final answer 100100.

Subtraction

Subtraction works in much the same way:

0 - 0 = 0
0 - 1 = 1 (with borrow)
1 - 0 = 1
1 - 1 = 0

One binary numeral can be subtracted from another as follows:

    *   * * *   (starred columns are borrowed from)
  1 1 0 1 1 1 0
-     1 0 1 1 1
-------------
= 1 0 1 0 1 1 1

Subtracting a positive number is equivalent to adding a
negative number of equal absolute value; computers typically use the two's complement notation to represent negative values. This notation eliminates the need for a separate "subtract" operation. For further details, see two's complement.

Multiplication

Multiplication in binary is similar to its decimal counterpart. Two numbers A and B can be multiplied by partial products: for each digit in B calculate the product of that digit and A and write this partial product on a new line, shifted leftward so that its rightmost digit lines up with the digit in B that was used. Finally, calculate the sum of all the partial products.

Since there are only two digits in binary, there are only two possible outcomes of each partial multiplication:

For example, the binary numbers 1011 and 1010 are multiplied as follows:

           1 0 1 1   (A)
         × 1 0 1 0   (B)
         ---------
           0 0 0 0   ← Corresponds to a zero in B
         1 0 1 1     ← Corresponds to a one in B
       0 0 0 0
   + 1 0 1 1
   ---------------
   = 1 1 0 1 1 1 0

Division

Binary division is again similar to its decimal counterpart:

        __________
1 0 1  | 1 1 0 1 1

Here, the divisor is 101, or 5 decimal, while the dividend is 11011, or 27 decimal. The procedure is the same as that of decimal
long division; here, the divisor 101 goes into the first three digits 110 of the dividend one time, so a "1" is written on the top line. This result is multiplied by the divisor, and subtracted from the first three digits of the dividend; the next digit (a "1") is included to obtain a new three-digit sequence:

             1
        __________
1 0 1  | 1 1 0 1 1
       - 1 0 1
         -----
           0 1 1

The procedure is then repeated with the new sequence, continuing until the digits in the dividend have been exhausted:

             1 0 1
        __________
1 0 1  | 1 1 0 1 1
       - 1 0 1
         -----
           0 1 1
         - 0 0 0
           -----
             1 1 1
           - 1 0 1
             -----
               1 0

Thus, the quotient of 11011 divided by 101 is 1012, as shown on the top line, while the remainder, shown on the bottom line, is 102. In decimal, 27 divided by 5 is 5, with a remainder of 2.

Bitwise logical operations

Though not directly related to the numerical interpretation of binary symbols, sequences of bits may be manipulated using Boolean logical operators. When a string of binary symbols are manipulated in this way, it is called a bitwise operation; the logical operators AND, OR, and XOR may be performed on corresponding bits in two binary numerals provided as input. The logical NOT operation may be performed on individual bits in a single binary numeral provided as input. Sometimes, such operations may be used as arithmetic short-cuts, and may have other computational benefits as well. See Bitwise operation.

Conversion to and from other numeral systems

Decimal

Written binary numbers often use the symbols 0 and 1. By way of comparison, the decimal numeral system uses the symbols 0 through 9. In either numeral system, digits in successively lower, or less significant, positions represent successively smaller powers of the radix. The starting exponent is one less than the number of digits in the number. A three-digit number would start with an exponent of two. In the decimal system, the radix is 10 (ten), so the left-most digit of a three-digit number represents the 102 (hundreds) position. Consider:

352 decimal is equal to:
3 times 102 (3 × 100 = 300) plus
5 times 101 (5 × 10 = 50) plus
2 times 100 (2 × 1 = 2)

In binary, the same relationship exists. Successively lower digits represent successively lower powers of the radix 2 (two), beginning with an exponent of n - 1, where n is the number of digits in the number. Consider a 5-digit binary number:

10110 binary is equal to
1 times 24 (1 × 16 = 16) plus
0 times 23 (0 × 8 = 0) plus
1 times 22 (1 × 4 = 4) plus
1 times 21 (1 × 2 = 2) plus
0 times 20 (0 × 1 = 0)

For a total of 2 + 4 + 16 = 22 in decimal. The left-most digit of this five-digit binary number represents the 24 position, or sixteens. The above procedure is one way to convert from binary into decimal.

The procedure for converting from decimal into binary is somewhat different. To convert from an integer decimal numeral to its binary equivalent, divide the number by two and place the remainder in the ones-place. Divide the result by two and place the remainder in the next place to the left. Continue until the result is zero.

An example:

Operation Remainder
118/2 = 59 0
59/2 = 29 1
29/2 = 14 1
14/2 = 7 0
7/2 = 3 1
3/2 = 1 1
1/2 = 0 1

Reading the sequence of remainders from the bottom up gives the binary numeral 1110110.

Hexadecimal

Binary may be converted to and from hexadecimal somewhat more easily. This is due to the fact that the radix of the hexadecimal system (16) is a power of the radix of the binary system (2). More specifically, 16 = 24, so it takes exactly four digits of binary to represent one digit of hexadecimal.

The following table shows each four-digit binary sequence along with the equivalent hexadecimal digit:

Binary Hexadecimal
0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010 A
1011 B
1100 C
1101 D
1110 E
1111 F

To convert a hexadecimal number into its binary equivalent, simply substitute the corresponding binary digits:

3A hexadecimal = 0011 1010 binary
E7 hexadecimal = 1110 0111 binary

To convert a binary number into its hexadecimal equivalent, divide it into groups of four bits. If the number of bits isn't a multiple of four, simply insert extra 0 bits at the left (called padding). For example:

1010010 binary = 0101 0010 grouped with padding = 52 hexadecimal
11011101 binary = 1101 1101 grouped = DD hexadecimal

Octal

Binary is also easily converted to the octal numeral system, since octal uses a radix of 8, which is a power of two (namely, 23, so it takes exactly three binary digits to represent an octal digit). The correspondence between octal and binary numerals is the same as for the first eight digits of hexadecimal in the table above. Binary 000 is equivalent to the octal digit 0, binary 111 is equivalent to octal 7, and so on. Converting from octal to decimal proceeds in the same fashion as it does for hexadecimal:

65 octal = 110 101 binary
17 octal = 001 111 binary

And from binary to octal:

101100 binary = 101 100 grouped = 54 octal
10011 binary = 010 011 grouped with padding = 23 octal

Representing real numbers

Non-integers can be represented by using negative powers, which are set off from the other digits by means of a radix point (called a decimal point in the decimal system). For example, the binary number 11.012 thus means:

1 times 21 (1 × 2 = 2) plus
1 times 20 (1 × 1 = 1) plus
0 times 2-1 (0 × (1/2) = 0) plus
1 times 2-2 (1 × (1/4) = 0.25)

For a total of 3.25 decimal.

All dyadic rational numberss p/2a have a terminating binary numeral -- the binary representation has only finitely many terms after the radix point. Other rational numbers have binary representation, but instead of terminating, they recur, with a finite sequence of digits repeating indefinitely. For instance

1/310 = 1/112 = 0.0101010101...2
1210/1710 = 11002 / 100012 = 0.10110100 10110100 10110100...2
The phenomenon that the binary representation of any rational is either terminating or recurring also occurs in other radix-based numeral systems. See, for instance, the explanation in Decimal. Another similarity is the existence of alternative representations for any terminating representation, relying on the fact that 0.111111... is the sum of the geometric series 2-1 + 2-2 + 2-3 + ... which is 1.

Binary numerals which neither terminate nor recur represent irrational numbers. For instance,

See also

Register, Unary numeral system, Ternary, Octal, Decimal, Hexadecimal, Floating point, p-adic numbers, truncated binary encoding.

External link