So you have a number in binary (or octal, hexadecimal, etc - your choice). You may understand how to use it in its own context, but its hard to conceptualize that number without it being in the common decimal system (Base 10) format. Below you will find out how to convert any number, of any base, to a comfortable and easy to understand decimal value. All your base are belong to us.

While you may never think of it like this, any number in decimal format can actually be represented by the sum of its digits multiplied by powers of ten. For example:

32764 = (3 x 10^4) + (2 x 10^3) + (7 x 10^2) + (6 x 10^1) + (4 x 10^0)

While most people are most familiar with numbers in base 10, this same method can be used to determine the decimal values for numbers of any base using five easy steps. The example below will show how to convert two common bases, Base 8 (octal) and Base 16 (hexadecimal), to Base 10, as well as a using the example on a number already in Base 10. For simplicity, the example will use a single number that is valid in all of these bases: 32764.

Before beginning, here are the answers that will be obtained. You may check them using any method of your choosing:

  • Octal to Decimal: 32764(8) = 13812(10)
  • Hexadecimal to Decimal: 32764(16) = 206692(10)
  1. Count the number of digits in the number. We will call this number N.
    Example:
    32764 has five digits, so N = 5
     
  2. Beginning with the least significant digit (i.e., the rightmost digit), start numbering the digits from 0 to N-1. We will call each of these numbers a "digit identifier".
    Example:
    4 3 2 1 0  <-- Digit Identifiers
    3 2 7 6 4
     
  3. Starting with the most significant digit (i.e., the leftmost digit), multiply this number by the base to the power of its "digit identifier"
    Examples:
    • Base 8 (Octal): (3 x 8^4)
    • Base 10 (Decimal): (3 x 10^4)
    • Base 16 (Hexadecimal): (3 x 16^4)
       
  4. Repeat Step #3 using the next digit to the right until you have used up all the digits.
    Examples:
    Base 8 (Octal)
    • Digit identifier 3: (2 x 8^3)
    • Digit identifier 2: (7 x 8^2)
    • Digit identifier 1: (6 x 8^1)
    • Digit identifier 0: (4 x 8^0)
    Base 10 (Decimal)
    • Digit identifier 3: (2 x 10^3)
    • Digit identifier 2: (7 x 10^2)
    • Digit identifier 1: (6 x 10^1)
    • Digit identifier 0: (4 x 10^0)
    Base 16 (Hexadecimal)
    • Digit identifier 3: (2 x 16^3)
    • Digit identifier 2: (7 x 16^2)
    • Digit identifier 1: (6 x 16^1)
    • Digit identifier 0: (4 x 16^0)
       
  5. Add up all the values.
    Examples:
    32764(8) (Octal) = (3 x 8^4) + (2 x 8^3) + (7 x 8^2) + (6 x 8^1) + (4 x 8^0) = 13812(10)
    32764(10) (Decimal) = (3 x 10^4) + (2 x 10^3) + (7 x 10^2) + (6 x 10^1) + (4 x 10^0) = 32764(10)
    32764(16) (Hexadecimal) = (3 x 16^4) + (2 x 16^3) + (7 x 16^2) + (6 x 16^1) + (4 x 16^0) = 206692(10)

I would like to acknowledge that there are other ways to convert a number of one base to base 10. However, these other methods are usually for converting one specific base to another specific base such as specifically oct to dec, hex to dec, bin to dec, etc. The method above works for converting any base to base 10.

in10se's method works, no doubt. It's very straightforward and follows directly from the definition of a written number as a polynomial. This is in fact how I implemented my first base-n converting program, back in Computer Science 101. But later on I came across Horner's method (currently a dead link in E2, but Horner's rule works), and I haven't looked back since.

In10se's approach is a bit cumbersome in that it calls for creating, at least temporarily, a table of powers of b, where b is the base. Done by hand, this calls for paper and scribbling thereon; done on a calculator, it requires memory slots.

With Horner's scheme, you can do the whole calculation with a series of additions and multiplications, without the need for additional storage. Also, you don't need to count up digits in the base b number; Horner works with numbers of arbitrary length, you just keep grinding the same two operations and just don't care about where it will end.

Enough propaganda! Here's where I put my money where my mouth is:

Algorithm to convert number xxx from base b to decimal

  • Start with 0 as your working number.
  • Repeat for each digit of xxx, working from left to right:
    • Add that digit to your current working number.
    • If you're not at the last digit
      • multiply your working number by b

Example: 327648

0
+ 3 = 3
× 8 = 24
+ 2 = 26
× 8 = 208
+ 7 = 215
× 8 = 1720
+ 6 = 1726
× 8 = 13808
+ 4 = 13812

On a simple-minded calculator that doesn't "do" algebraic notation, i.e. arithmetic precedence of multiplication over addition, you can bash this sequence in verbatim:

3 × 8 + 2 × 8 + 7 × 8 + 6 × 8 + 4 =

On a more sophisticated calculator, you need to insert some more equalses:

3 × 8 + 2 = × 8 + 7 = × 8 + 6 = × 8 + 4 =

In a pinch, if you don't have a calculator, you can probably do the calculation in your head: You only need to keep one "big" number in memory (apart from the original one); and so long as your base is less than 10, all your multiplication will be by a single digit number, which many people manage mentally. Failing that, it's easy enough to do with paper and pencil.

Simple, huh? Of course the credit goes to the bright folks who think this stuff up. In mathematics as in all of science, we are fortunate to be standing on the shoulders of giants.

Log in or registerto write something here or to contact authors.