Encyclopedia > Base 2

  Article Content

Binary numeral system

Redirected from Base 2

The binary or base-two numeral system is a representation for numbers that uses a radix of two. It was first described by Gottfried Leibniz, and is used by most modern computers because of its ease of implementation using digital electronics--early 20th century computers were based the on/off and true/false principles of Boolean algebra. Binary can be considered the most basic practical numeral system (the Unary system is simpler, but impractical for most computation).

Table of contents

Representation

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

 0101001101011
 on off off on off on
 + - - + - +
 Y N N Y N Y

In keeping with customary representation of numerals using decimal digits, 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. As we will see, the binary numeral "100" is equal to the decimal value 4, so it would cause confusion to refer to the numeral as "one hundred."

Counting in Binary

Counting in binary is similar to counting in any other number system. When the symbols representing successively higher values are exhausted, the next-higher digit is incremented, and counting begins at 0. In decimal, counting proceeds like so:

00, 01, 02, ... 07, 08, 09, 10, 11, 12, ... 17, 18, 19, 20...

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

000, 001, 010, 011, 100, 101, 110, 111...

Binary Arithmetic

Arithmetic in binary is much like arithmetic in other numeral systems. Addition, subtraction, multiplication, and division can be performed on binary numerals. 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, we "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 works in much the same way:

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

In the binary system, however, it is customary to use the two's complement[?] notation for performing subtraction. Briefly stated, this notation represents a negative number, which can then be added to the first number to achieve the operation of subtraction.

In binary, multiplying by two amounts to moving all digits one position to the left and inserting a leftmost zero. This observation leads to the following faster conversion algorithm, a variant of the Horner scheme which does not require the computation of the powers of two: start with a result of zero and scan over the binary string from left to right. If the current digit in the string is a zero, multiply the result by two; if the current digit is a one, multiply the result by two and add one. Continue until you hit the right end of the binary string. Example:

To convert the binary number 101101001 into decimal: 0 × 2 + 1 = 1, 1 × 2 = 2; 2 × 2 + 1 = 5; 5 × 2 + 1 = 11; 11 × 2 = 22; 22 × 2 + 1 = 45; 45 × 2 = 90; 90 × 2 = 180; 180 × 2 + 1 = 361.

Bitwise Logical Operations

It is frequently useful to perform logical operators to binary numerals. Usually, these are done on a bit-wise basis—that is, they are performed on each digit (or bit) individually. The logical operators AND, OR, XOR, and NOT are commonly used.

Binary Compared with 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 positions represent successively smaller powers of the radix. The starting exponent is one less than the number of digits in the number. For a three-digit number, we would start with an exponent of two. In the decimal system, the radix is 10, 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, 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:

OperationRemainder
118/2 = 590
59/2 = 291
29/2 = 141
14/2 = 70
7/2 = 31
3/2 = 11
1/2 = 01

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

Binary Compared with 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 4 digits of binary to represent one digit of hexadecimal.

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

BinaryHexadecimal
00000
00011
00102
00113
01004
01015
01106
01117
10008
10019
1010A
1011B
1100C
1101D
1110E
1111F

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

Binary Compared with 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:

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

Representing Fractional 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). The binary number 11.01 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.

See also: Register, Unary, Ternary, Octal, Decimal, Hexadecimal, Floating point, p-adic numbers, truncated binary encoding.



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
1904

... March 28 - Werner Bahlsen[?], biscuit[?] producer (+ 1985) April 3 - Sally Rand[?], dancer (+ 1979) April 7 - Ralph Bunche[?], diplomat, winner of the Nobel Peac ...

 
 
 
This page was created in 23.2 ms