Contents  Mathematics > Base conversion 
 

This short tutorial explains how to convert between different bases, including binary.

Converting decimal to binary (or another base):

Converting a base 10 number to binary (base 2) is very straightforward. You repeatedly divide the number by 2, each time recording the remainder. At the end of this line up all of the remainders and reverse their order. For example:

Converting 20 (dec) to binary - step 1

20/2 = 10 (+ remainder 0)
10/2 = 5 (+ remainder 0)
5/2 = 2 (+ remainder 1)
2/2 = 1 (+ remainder 0)
1/2 = 0 (+ remainder 1)

Once the answer (without remainder) equals 0, stop. The remainders from each division were: 0,0,1,0,1, reverse these digits to get the result. 20dec = 10100bin

By replacing 2 with a different number, one can convert to that base. Here's an example showing 14dec being converted to base 8 (octal):

Converting 14dec to octal
14/8 = 1 (6 remainder)
1/8 = 0 (1 remainder)

The remainders were 6,1, reversed this is 16

14dec = 16oct

So what about hexadecimal? The process is the same, but with one extra thing to keep in mind: hexadecimal is base 16, and hence makes use of 6 extra symbols (ABCDEF). A = 10, and F, 15. 16 is written as 10. When converting to any base above 10 you must keep in mind that a remainder above equal to or greater than 10 has to be written using the correct symbol.

Converting 1446dec to hexadecimal
1446/16 = 90 (6 remainder)
90/16 = 5 (10 remainder)
5/16 = 0 (5 remainder)

The remainders were 6,10,5. 

10 should be written as A. Reversed, this equals 5A6

1446dec = 5A6hex

Converting binary (or another base) to decimal:

A decimal number can be represented as 100s, 10s and units, so 234 is 2 hundreds, 30 tens and 4. Each digit in a number has a place value and a face value. The face value is a number's actual value, while the place value is a digit's value in the base to which it belongs, and depends on its position in the number. These are illustrated in the next example:

Place values:
Number:    1589

Number:     1        5     8   9
Face value: 1        5     8   9
Place value: 1000 100 10 1

Knowing this, it is possible to convert between bases easily. The next example converts 11011bin to decimal:

Step 1: find the place value and face value of each digit:

Digit:            1   1  0 1  1
Face value:   1   1  0 1  1
Place value:  16 8  4  2 1

Step 2: Multiply each digit's face value by its place value and add all together:

(1*16)+(1*8)+(0*4)+(1*2)+(1*1)
16+8+2+1 = 27

11011bin = 27dec

It may seem a bit unnecessary to bother with face values for binary conversion, however with higher bases you can see why these are important. The next example shows how to convert 4C9hex to decimal:

Digit :          4      C  9
Face value : 4     12  9 (Reminder: C means 12 - A=10,B=11,C=12,D=13,E=14,F=15)
Place value: 256 16  1

(256*4)+(16*12)+9
1024+192+9 = 1225

4C9h = 1225d

Copyright © 2003-2007 Matt Squire. All rights reserved. No content may be duplicated without express written permission.
Hand coded by a thousand monkeys under the direction of Matt Squire
contact: mattsquire at insidereality dot net | Legal stuff

What you need is a cow; I'm fairly sure that a cow would solve all your problems