Skip to main content

Section 4.3 Binary Conversions - Multiplication/Division Method

The biggest issue with the โ€œtable methodโ€ shown on the previous page is that it is hard to translate into an algorithm that a machine could run. The multiplication/division methods shown on this page are much easier to express in simple terms as they rely on mathematics instead of looking at a table and making a decision.

Subsection 4.3.1 Decimal to Binary

The following algorithm converts a decimal number to a binary one:
Step 1: Start with a blank answer and the number you are converting Step 2: Divide your number by 2 to make
       a quotient and a remainder Step 3: Place your remainder on the left side of your answer Step 4: If your quotient
       is 0, you are done Otherwise, make the quotient your new number and go back to step 2
Here is an example of running the algorithm to convert \({11}_{10}\) to binary:
Animation used by permission of Virginia Tech
So the decimal number 11 in binary is \({1011}_{2}\text{.}\)

Subsection 4.3.2 Binary to Decimal

To convert a binary number to its decimal value, we can use almost the same trick, but in reverse:
Step 1: Start with the 'number' you are converting and the 'answer' of 0 Step 2: Multiply your 'answer' by
       2 Step 3: Remove the leftmost digit of 'number' and add it to your 'answer' Step 4: If 'number' has no more
       digits, you are done Otherwise, go back to step 2
If we follow this algorithm to convert \({1101}_{2}\) into a decimal value, it would look like this:
Step 1: 'number' is 1101 and 'answer' is 0 Step 2: 'answer' is multiplied by 2 - it becomes 0 Step 3:
       Remove the leftmost digit of 'number' and add it to 'answer' 'number' is now 101 and 'answer' is 1 Step 4:
       'number' still has digits, go back to step 2 Step 2: 'answer' is multiplied by 2 - it becomes 2 Step 3: Remove
       the leftmost digit of 'number' and add it to 'answer' 'number' is now 01 and 'answer' is 3 Step 4: 'number'
       still has digits, go back to step 2 Step 2: 'answer' is multiplied by 2 - it becomes 6 Step 3: Remove the
       leftmost digit of 'number' and add it to 'answer' 'number' is now 1 and 'answer' is 6 Step 4: 'number' still has
       digits, go back to step 2 Step 2: 'answer' is multiplied by 2 - it becomes 12 Step 3: Remove the leftmost digit
       of 'number' and add it to 'answer' 'number' is now "" (empty) and 'answer' is 13 Step 4: 'number' is empty. We
       are done, the 'answer' is 13.
As mentioned earlier, the advantage of this algorithm is that it very easily converts into relatively simple computer code. To demonstrate that, the algorithm is implemented in Python in the codelens below. You DO NOT need to worry about exactly how the Python language works. You will notice that turning the English algorithm above into code requires some changes, but the code shown follows the same process described above. See the โ€œtipsโ€ box below the code lens for help running the program.

Note 4.3.1.

How to use the โ€œcodelensโ€
  • You can click the โ€œforwardโ€ button to watch the code run line by line.
  • Use can use the large gray scroll bar beneath the code to scroll the code to the right - at the end of each line of code is an explanation of what that line โ€œsaysโ€
  • The blue โ€œGlobal frameโ€ area that appears at the bottom will display the current value of number and answer.

Checkpoint 4.3.2.

If you use the division method to convert decimal 49 to binary, how many times do you have to do step 2 (divide the number by 2)?
  • 5
  • You are dividing by 2 until you reach 0. 5 divisions wonโ€™t get you there
  • 4
  • You are dividing by 2 until you reach 0. 4 divisions wonโ€™t get you there
  • 6
  • 49
  • You are dividing by 2 until you reach 0. donโ€™t need that many divisions

Checkpoint 4.3.3.

Hint.
\({2}_{11010}\) is 26 in decimal. You can check your answer by making sure it equals 13 in decimal. But you shouldnโ€™t have to do math to figure out the answer.

Checkpoint 4.3.4.

Hint.
Each shift to the left multiplies the number by 2. How many shifts are needed to multiply by 8?
You have attempted of activities on this page.