How to convert binary numbers to decimal numbers

From ArticleWorld


The vast majority of today's computers use the binary system. It is not important for our discussion to explain why, but, as a future programmer, you should understand the importance of this. Therefore, you should be able to convert between the two bases.

How number bases work

The natural base we use is the decimal (base 10) base. We use it because of a simple reason: when people discovered abstract numbers (managing to unbind the number from its physical representation), the most common support they had for counting was their fingers. People had ten fingers. If you take ten fingers ten times, you have 100 fingers. Take these ten more times, and you have 1000 fingers.

Therefore, a the number 123 is represented, in the decimal base, as:

1 * 10^2 + 2 * 10^1 + 3 * 10^0

The quick abstraction is: computers only have two fingers, so they use base 2. But the mechanism is the same.

Conversion

What we use for conversion is a "base 2 table". A base ten table looks like this:

...1000    100    10    1

In other words, all the powers of ten. The base 2 table is similar, but uses the powers of two:

...256     128     64    32    16    8    4    2    1

Now, in order to convert a number:

  1. Write the base two table on a sheet of paper. The table should have the length of the number. Therefore, if the binary number has 8 digits, you should start the table with 256 (2^7). Write the number you wish to convert underneath:
...256     128     64    32    16    8    4    2    1


   1       1       1     0     0     1    0    1    1
  1. Now multiply each number in the base two table with the number it has underneath. Write the results underneath, and sum them up.
...256     128     64    32    16     8    4    2    1

    *       *       *     *     *     *    *    *    *
  
    1       1       1     0     0     1    0    1    1
-------------------------------------------------------
  256  +   128   + 64  +  0  +  0  +  8  + 0  + 2  +1


Which makes 459. Therefore, 111001011 is 459.

Notes

This may seem a little awkward at first, but in fact is is quite easy. With some practice, you will eventually be able to make the conversion in your head. Try to memorize the sequence of two's powers.