# Base conversions: Math help, please.



## Sage Noctowl (Apr 4, 2010)

Okay, well, I've been working on a base-converting project, and I've figured out the easy conversions (How to Convert Octal to Quaternary, as shown in the attachment), but I seem to be stuck.  According to the direction I'm going, to convert from binary to decimal, I have to group the numbers into groups of 1/log(2), which just isn't happening.  There has to be some way to do it, and I was wondering if your brilliant minds could help me.
Thanks in advanced.


----------



## Butterfree (Apr 4, 2010)

Um, just add together the powers of two corresponding to the placement of the ones in the binary representation?

100101 = 2^5 + 2^2 + 2^0 = 32 + 4 + 1 = 37.


----------



## Sage Noctowl (Apr 4, 2010)

Yeah, that's the way I thought, but what happens when you have a harder problem that you can't do manually?  For example, trying to convert from octal to a base 7 system, with 20 digits?  Again, I can't group in terms of "log (7)/log (8)", because it would create an irrational fraction.


----------



## 1. Luftballon (Apr 4, 2010)

logs 2/10 is irrational, too. try to stop complicating things for yourself. this kind of stuff requires the proper mindset to approach.


----------



## Kali the Flygon (Apr 10, 2010)

How worried about performance are you? a simple, though probably not fastest flop-wise, way to convert between the two bases would be to recursively divide the number by the second base, and record the remainders as your new number.

for instance, converting decimal to binary:
168273
quotient | remander
 84136 | 1
 42068 | 0
 21034 | 0
 10517 | 0
  5258 | 1
  2629 | 0
  1314 | 1
   657 | 0
   328 | 1
   164 | 0
    82 | 0
    41 | 0
    20 | 1
    10 | 0
     5 | 0
     2 | 1
     1 | 0
     0 | 1

Collecting the remainders from last (left) to first (right), we have 101001000101010001, so 168273 in base 10 = 101001000101010001 in base 2. Would that help?


----------

