Drexel dragonThe Math ForumDonate to the Math Forum

Ask Dr. Math - Questions and Answers from our Archives
_____________________________________________
Associated Topics || Dr. Math Home || Search Dr. Math
_____________________________________________

Converting a Number from One Base to Another

Date: 02/28/2008 at 17:03:31
From: Shayan
Subject: conversion of any base to binary

How to convert a number in any base to binary?  For example, 673.6 of
base 8 to binary and 310.2 of base 4 to binary?

I know conversion of decimal to binary but what about conversion of 
octal or hexadecimal to binary?

Now I convert octal 673.6 to decimal then to binary but I want to get
direct method to convert octal 673.6 to binary.



Date: 02/28/2008 at 22:09:26
From: Doctor Greenie
Subject: Re: conversion of any base to binary

Hi, Shayan --

Your question asks about the method for converting from any base to 
binary; but your examples only ask about converting from base 4, base 
8, or base 16.

Conversion from bases 4, 8, or 16 to base 2 is easy, because those 
bases are powers of 2.  As a result, each digit in base 4 converts 
directly to two digits in binary; each digit in base 8 converts 
directly to three digits in binary; and each digit in base 16 
converts directly to four digits in binary.

So for your examples we have

  673.6 (base 8) = 110 111 011 . 110 (binary)
  310.2 (base 4) = 11 01 00 . 10 (binary)

- Doctor Greenie, The Math Forum
  http://mathforum.org/dr.math/ 



Date: 03/01/2008 at 08:32:02
From: Shayan
Subject: conversion of any base to binary

Thank you. Is there any direct method to convert octal to hexa or any
base to any other base?



Date: 03/01/2008 at 22:57:18
From: Doctor Greenie
Subject: Re: conversion of any base to binary

Hello, Shayan --

There is a single method that can be used to convert any number from 
one base directly to another base, without going through base 10.  You
just need to be able to perform multiplication and addition in the new
base.

I will demonstrate the process below.  However, first, here is a 
link to a page in the Dr. Math archives where standard methods are 
described for converting numbers between base 10 and another base:

  Converting from Base 6 to 10 and Back
    http://mathforum.org/library/drmath/view/55738.html 

Here is a section quoted from that page, showing the conversion of a 
number from base 6 to base 10.  We will use this method to convert 
from any base to any other base; this example of converting to base 
10 is useful because it uses our familiar base 10 arithmetic.  As 
noted in my opening paragraph, we can use the same process to 
convert to any other base, as long as we can do the required 
arithmetic in the new base.

*****************************

*** Base 6 to Base 10, Fast Method
----------------------------------

To convert 1524 (base 6) to base 10 with the fast method, we start 
with the leftmost digit and move right; at each step we multiply by 
6 and add the next base-6 digit, until we have used all the digits.  
For the conversion of 1524 (base 6) to base 10, the process is as 
follows:

                                               base-6 equivalent of
      action                  base-10 value    this base-10 value
  -----------------------------------------------------------------
  get first base-6 digit (1)         1                1
  multiply by 6                      6                10
  add next digit (5)                11                15
  multiply by 6                     66                150
  add next digit (2)                68                152
  multiply by 6                    408                1520
  add last digit (4)               412                1524

In this process, we find the base-10 equivalent of our base-6 number 
by "building" the base-6 number from left to right. We start with 
the leftmost base-6 digit, 1; when we multiply by 6, we get the base-
10 equivalent of the base-6 number 10, and when we then add the next 
base-6 digit (5), we get the base-10 equivalent of the base-6 number 
15; when we again multiply by 6 and add the next base-6 digit (2), 
we get the base-10 equivalents of the base-6 numbers 150 and then 
152; and, finally, when we multiply again by 6 and then add the last 
base-6 digit (4), we get the base-10 equivalents of the base-6 
numbers 1520 and finally 1524.

*****************************

Now let's use exactly the same method to convert 1524 base 6 to base 
8 instead of to base 10.  We can copy the first column of the table 
above exactly as it is, because the actions we take to perform the 
conversion are exactly the same.  But the results in the second 
column will be different, because now all the arithmetic we are 
doing is in the new base, 8.

                                               base-6 equivalent of
      action                  base-8  value    this base-8 value
  -----------------------------------------------------------------
  get first base-6 digit (1)         1                1
  multiply by 6                      6                10
  add next digit (5)                13                15
  multiply by 6                    102                150
  add next digit (2)               104                152
  multiply by 6                    630                1520
  add last digit (4)               634                1524

We can verify this result by converting it to base 10, again using 
exactly the same process.  The result we get should of course be the 
original number, 412.  This time, since we are converting to base 
10, the arithmetic is in our familiar base 10:

                                               base-8 equivalent of
      action                  base-10 value    this base-10 value
  -----------------------------------------------------------------
  get first base-8 digit (6)         6                6
  multiply by 8                     48                60
  add next digit (3)                51                63
  multiply by 8                    408                630
  add next digit (4)               412                634

We could also convert the base-6 number 1524 directly to base 4 
using the same method.  This time the conversion is a bit more 
difficult, because some of the base-6 digits are 2-digit numbers in 
base 4 (4 base 6 is "10" base 4; 5 base 6 is "11" base 4).  And 
the "6" we have to multiply by each time is "12" in base 4.  So the 
conversion looks like this -- with all the arithmetic in base 4:

                                               base-6 equivalent of
      action                  base-4 value     this base-4 value       
  -----------------------------------------------------------------
  get first base-6 digit (1)         1                1
  multiply by "12"                  12                10
  add next digit (5 = "11")         23                15
  multiply by "12"                1002                150
  add next digit (2)              1010                152
  multiply by "12"               12120                1520
  add last digit (4 = "10")      12130                1524

And finally we can use the same process again (using base 10 
arithmetic) to convert this result to base 10 and verify that we get 
the correct value of 412:

                                               base-4 equivalent of
      action                  base-10 value    this base-10 value
  -----------------------------------------------------------------
  get first base-4 digit (1)         1                1
  multiply by 4                      4                10
  add next digit (2)                 6                12
  multiply by 4                     24                120
  add next digit (1)                25                121
  multiply by 4                    100                1210
  add next digit (3)               103                1213
  multiply by 4                    412                12130
  add next digit (0)               412                12130

I hope all this helps.  Please write back if you have any further 
questions about any of this.

- Doctor Greenie, The Math Forum
  http://mathforum.org/dr.math/ 



Date: 03/02/2008 at 07:07:15
From: Shayan
Subject: Thank you (conversion of any base to binary)

Thank you very much for directing me to the right path.
Associated Topics:
Middle School Number Sense/About Numbers

Search the Dr. Math Library:


Find items containing (put spaces between keywords):
 
Click only once for faster results:

[ Choose "whole words" when searching for a word like age.]

all keywords, in any order at least one, that exact phrase
parts of words whole words

Submit your own question to Dr. Math

[Privacy Policy] [Terms of Use]

_____________________________________
Math Forum Home || Math Library || Quick Reference || Math Forum Search
_____________________________________

Ask Dr. MathTM
© 1994-2013 The Math Forum
http://mathforum.org/dr.math/