TechnologyUK - Number Systems Logo

Binary Numbers

The binary (or base 2) number system is a positional number system that represents numeric values using two symbols - zero (0) and one (1). For this reason, it is said to have a radix of 2. Binary values are stored using transistorised switches in microprocessors and memory chips, and can be manipulated using digital logic circuitry. For this reason, the binary number system is used by computer hardware to carry out all machine-level operations, and to store data in working memory. The bulk storage of non-volatile data on magnetic disk and optical media is also possible largely due to the simple two-state nature of binary values. Binary numbers are expressed as a series of one or more binary digits (bits), occasionally with the suffix 2 to indicate that they are in fact binary (base 2) numbers. Here is the decimal number 170 expressed as a binary number:

101010102

Like the decimal system with which we are familiar, the position of each digit within a binary number determines its value. Whereas each position in a decimal number represents some power of 10, however, each position in a binary number represents a power of 2. The table below shows the numbers 0 to 15 (to base 10) as 4-bit binary numbers (15 is the largest number that can be expressed using four binary digits).

BinaryDecimalBinaryDecimal
0000010008
0001110019
00102101010
00113101111
01004110012
01015110113
01106111014
01117111115

The decimal number 15 expressed as a binary number (1111) is therefore:

1x23+1x22+1x21+1x20 (8+4+2+1=15)

The binary digit in the right-most position in any binary whole number holds the smallest value (with a maximum value of 1) and is sometimes referred to as the least significant bit (LSB). The left-most binary digit has a maximum value that reflects its position relative to the LSB, and will be some power of 2 greater than 0. The left-most binary digit (assuming that we ignore leading zeros) is sometimes referred to as the most significant bit (MSB), and its value always exceeds the combined value of all the bits to the right of it. For this reason, the overall magnitude of a binary number is always determined by the position of the left-most (non-zero) bit.

Fractions can also be represented using binary digits, as can real (fractional) numbers. Like real numbers to base 10, the fractional part of a binary number follows a period. In the decimal number system we call this a decimal point, but in the binary number system we call it a binary point. In the decimal system, the numeral in the first position following the decimal point is multiplied by 10-1 (0.1), the digit in the second position following the decimal point is multiplied by 10-2 (0.01), and so on. The fractional part of a binary number works on the same principle, except that the digit in the first position following the binary point is multiplied by 2-1 (0.5 to base 10), the digit in the second position following the binary point is multiplied by 2-2 (0.25 to base 10), and so on. Note that, whereas each successive positive power of 2 has double the value of its predecessor, each successive negative power of 2 has half the value of its predecessor. The anatomy of a real binary number is illustrated below.


The anatomy of a real binary number

The anatomy of a real binary number


It can be seen from the above that converting binary numbers to decimal is relatively straightforward. Simply add together the powers of 2 represented by each binary digit that has a value of 1 (this works for binary integers, fractions, and real numbers). Almost as obvious, when you think about it, is the fact that the precision with which real numbers and fractions (to base 10) can be converted to binary will often depend on the number of bits available to represent the fractional part of the number. The greater the number of bits used, the more accurate the result will be (in computing terms, greater accuracy equates to more memory space required to store the result).


Converting decimal numbers to binary

Converting decimal numbers to binary is not quite so straightforward, but it is not all that difficult. To make things easier, we will deal with whole numbers and fractions (or the whole number and fractional parts of real numbers) separately. Let’s start with binary integers ("integer" is the name we use for a whole number). The method described here is one of several that can be used, but is probably the most straightforward. To convert a decimal number n to binary proceed as follows:

  1. Divide n by 2, and write down the remainder (0 or 1).
  2. If the result of the previous step is greater than 0, divide it by 2 and write down the remainder. Otherwise, go to step 4.
  3. Repeat step 2.
  4. Write down the sequence of remainder values in reverse order.

The following example should clarify this process. We are going to convert the decimal number 169 to its binary equivalent.


Decimal-to-binary integer conversion

Decimal-to-binary integer conversion


The binary number is read from the remainder column starting with the bottom-most bit (the most significant bit, or MSB) and ending with the top-most bit (the least significant bit, or LSB), giving us a binary value of:

101010012 (16910)

Converting decimal fractions to binary is a similar process. As with the integer conversion described above, the method shown below is not the only one available, but is relatively easy to use. It can be used for fractional values expressed either as proper fractions (e.g. ¾) or decimal fractions (e.g. 0.75). To convert a decimal fraction to binary, proceed as follows:

  1. Start by writing the binary point, preceded by a zero.
  2. Multiply the fractional value by 2.
  3. If the result is less than 1, add a 0.
  4. If the result is 1 exactly, add a 1 and go to step 7.
  5. If the result is greater than 1, add a 1 and discard the integer part of the result to create a new fractional value.
  6. Go to step 2.
  7. Stop.

The following example illustrates how the process works. We are going to convert the fraction 1/3 to its binary equivalent.


Decimal-to-binary conversion of a fractional value

Decimal-to-binary conversion of a fractional value


It should quickly become apparent that the decimal fraction being converted is in this case represented by a repeating binary pattern. The accuracy (or precision) of the conversion will therefore depend upon how many bits are available to hold the fractional value. In this case, we have allowed 6 bits to the right of the binary point, giving us a binary value of:

0.0101012

Note that 1/3 expressed as a decimal fraction is 0.333 recurring, and the accuracy of the decimal representation is thus dependent on the number of decimal places to which the value is given. When carrying out calculations involving fractional values, therefore, it is always a good idea to determine the degree of accuracy required for the answer. For binary calculations, there will usually be some upper limit on the number of bits available for the fractional part of the result.