This subsection discusses the conversion process between decimal and binary numbers.

The conversion from binary is actually simpler than you might think at first. There are five main steps:

- Start by placing a 2
^{0}above the rightmost bit. - Place 2's across the rest of the bits.
- Starting from the right, place an exponent for each 2 so that it is
counting up from 2
^{0} - Now, multiply each bit by the power of 2 above it, i.e., 1 * 2
^{2}. - Finally, to get the decimal equivalent, add all of the numbers from the previous step and that is the decimal equivalent.

Here is an example of the conversion of the binary number 1110 0010:

Place 2^{0} above the right most bit

2^{0} |
|||||||

1 | 1 | 1 | 0 | 0 | 0 | 1 | 0 |

Place 2's above all of the bits, like in step 1 (just without the exponent).

2 | 2 | 2 | 2 | 2 | 2 | 2 | 2^{0} |

1 | 1 | 1 | 0 | 0 | 0 | 1 | 0 |

Starting from the right, place exponents on the 2's so that it counts up from the right.

2^{7} |
2^{6} |
2^{5} |
2^{4} |
2^{3} |
2^{2} |
2^{1} |
2^{0} |

1 | 1 | 1 | 0 | 0 | 0 | 1 | 0 |

Multiply each bit by the power of 2 above it.

Powers of 2: | 2^{7} |
2^{6} |
2^{5} |
2^{4} |
2^{3} |
2^{2} |
2^{1} |
2^{0} |

Bits: | 1 | 1 | 1 | 0 | 0 | 0 | 1 | 0 |

Multiplied result: | 2^{7} |
2^{6} |
2^{5} |
0 | 0 | 0 | 2^{1} |
0 |

Add all of the results from the previous step and the result will be the decimal equivalent.

$ \text{Decimal Equivalent} = 2^7 + 2^6 + 2^5 + 2^1 = 128 + 64 + 32 + 2 = 226 $

A table of powers of two can help with conversions and further cement that bit positions have solid values.

The conversion process from decimal to binary is a little more involved since the faster (more efficient) way requires the use of logarithms, but there is a simpler but more involved process where you look for the largest power of 2 in the number. The 8 steps for some decimal number $D$, using the logarithm method, are:

- Take the $log_2$ of $D$.
- Round the result from step 1 down, we will call this result $P$ and write this down in a separate area, since these values are the positions of the 1's.
- Using the decimal number, subtract $2^P$ from it, this will be our new decimal number (i.e., $D_\text{new}=D-2^P$). Repeat steps 1 through 4 until $D=0$.
- Now that you have all the powers of 2 that were in the original $D$, arrange them from left to right largest to smallest, with extra space for each number skipped.
- Write 1's below the numbers and 0's below the extra space (remember there is a 0 bit position!).
- The result should be the equivalent binary number (check with an online converter to be sure!).

An example conversion should help clear up how the process works. We will convert 192 into binary:

- Find $log_2 D$
- $log_2 192 = 7.58$

- Round the result in step 1 down, $P = 7$, and write it down nearby.
- $7$

- Now, subtract $2^P$ from our number and this resulting number will be our next starting number until the result is 0.
- $2^P = 2^7 = 128$
- $D = 192 - 128 = 64$

- $log_2 64 = 6$

- $P = 6$
- $7,6$

- $2^6 = 64$
- $D = 64 -64 = 0$

Since $D$ is now $0$, we will arrange our written numbers from left to right, largest to smallest, and spaces for numbers skipped. (Remember that 0 should be included/is the last number).

7 | 6 |

Write 1's below the values written in, and 0's for the blank spaces.

7 | 6 | ||||||

1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |

The binary number is the sequence of bits you just filled in (in step 7). This result can be confirmed with an online binary converter. Such as the one here.

The other method of converting from decimal to binary is by finding the largest power of 2 in that number, and then subtracting it, and repeating until the result is 0. Recording each power until we stop. This is the more intuitive method that may be easier, especially with a table of the powers of 2 to help speed the process up. Like the table above(which only goes up to $2^8$).

The main process of this method is as follows:

- Find the highest power of 2.
- Subtract it from the current number.
- Write down the power of 2 used. Repeat steps 1 through 3 until the number is 0.
- Like the previous method, write the numbers out left to right, highest to smallest, leaving spaces between powers of 2.
- Write 1's under the powers of 2 written in, and 0's under the blanks, remember that 0 is a power of 2, and the result will be the binary number. This can be confirmed in the link given in the previous example.

Using the previous example number of 192, we will find the highest power of 2 that fit into it. This power of 2 is $2^7$, which is 128.

We subtract the current number, 192, by the power of 2 we found to get our next current number.

$192-128=64$

Write down the power of 2 we used and go back to step 1 until we hit 0.

$7$

We find that the highest power of 2 that fits into 64, is 64, which is $2^6$.

We subtract our numbers to get the next number.

$64-64=0$

We write down the power of 2, and break out of our loop since we hit 0.

$7 6$

Write out the powers of two we used, leaving blanks for the numbers we didn't use.

$7$ | $6$ |

Write 1's under the powers of 2 that are filled in, and 0's under the blank spaces.

$7$ | $6$ | ||||||

1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |

This number is 1100 0000 and can be confirmed by the process we used above, and in the binary converter that is also linked above as well.

*Other product and company names mentioned herein are trademarks or trade names of their respective companies. © 2014 Digilent Inc. All rights reserved.*