Number Base Conversions

 

Base 2 to Base 10

In base 2, each column value represents a power of 2, starting with a value of 20 in the rightmost column, and increasing in each column moving left.

215 214 213 212 211 210 29 28 27 26 25 24 23 22 21 20
32768 16384 8192 4096 2048 1024 512 256 128 64 32 16 8 4 2 1

To convert a base 2 number to base 10, note that the value contributed by a column containing 0 is 0, and the value contributed by a column containing 1 is (1 * [the column value]) or just the column value. Thus to get the base 10 representation, add the column values for all columns that contain a 1. For example, consider 101101012.

27 26 25 24 23 22 21 20
128 64 32 16 8 4 2 1
1 0 1 1 0 1 0 1

Therefore

     101101012 = (128 + 32 + 16 + 4 + 1)10
               = 18110

An easier way to compute this is to start at the rightmost digit, with column value 1. As you move left, each column value is twice the previous value. Starting at the right, note the value of each column that contains a 1, and then add them up. Starting from the right makes it unnecessary to remember the column values; you can easily compute them as you move left. For example, consider 1110011002. From right to left, the column values containing 1's are:

     4 + 8 + 64 + 128 + 256 = 460

Therefore, 1110011002 = 46010

Base 10 to Base 2

We will present two methods to convert base 10 to base 2. One uses subtraction and the other uses division.

Given a base 10 number N, the subtraction method works by finding the largest power of 2 which is less than or equal to N. Place a 1 in that column of the base 2 number, and then subtract that power of 2 from N, resulting in N1. Repeat using N1, and continue until the resulting Nk is zero. Place a 0 in each column whose column value was never subtracted. For example, let N = 182:

     128 ≤ 182 < 256 so place a 1 in the 128 column
     182 - 128 = 54

     32 ≤ 54 < 64  so place a 1 in the 32 column
     54 - 32 = 22

     16 ≤ 22 < 32 so place a 1 in the 16 column
     22 - 16 = 6

     4 ≤ 6 < 8 so place a 1 in the 4 column
     6 - 4 = 2

     2 ≤ 2 so place a 1 in the 2 column
     2 - 2 = 0 so we're done

     now put a zero in all other columns to get 18210 = 101101102

The disadvantage of the subtraction method is that it requires knowledge of the powers of 2. The division method is more mechanical. Given a base 10 number N, divide N by 2 using integer division. The remainder is the least significant digit of the binary representation. The quotient is divided by 2 and its remainder becomes the next digit. This method is repeated until the quotient is 0. For example, let N = 182:

     182 / 2 = 91 rem 0
      91 / 2 = 45 rem 1
      45 / 2 = 22 rem 1
      22 / 2 = 11 rem 0
      11 / 2 =  5 rem 1
       5 / 2 =  2 rem 1
       2 / 2 =  1 rem 0
       1 / 2 =  0 rem 1

     18210 = 101101102

Remember to use the remainders in the correct order: the first remainder is the low order digit and the last remainder is the high order digit.

Base 2 to Base 16

Recall the first 16 numbers in base 2 and base 16:

Base 2 Base 16
0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
1010 A
1011 B
1100 C
1101 D
1110 E
1111 F
  1. Starting from the rightmost digit of the base 2 number, group the digits into groups of 4. The leftmost group may have less than 4 digits.
  2. Translate each group into the corresponding hex digit.

For example:

     101100011000012 = 10 1100 0110 00012
                     = 2C6116

Base 16 to Base 2

Translate each hex digit into the corresponding base 2 number, using 4 binary digits for each hex digit.

For example:

     D04F316 = 1101 0000 0100 1111 00112
             = 110100000100111100112

Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2009