Click to See Complete Forum and Search --> : Converting from/to base x


Gnu/Vince
01-23-2002, 07:41 PM
Could anyone tell me how to convert from base x to base y and vice versa where x and y are arbitrarily chosen? Thanks. I can't remember logarithmic...

nuisance
01-23-2002, 08:12 PM
Change of Base Formula


log n1 = log n1 / log b1
b1 b2 b2


b1 = base converting from
n1 = number being converted
b2 = base converting to

what you get on the right side is your solution

Is this what you were looking for?

[ 23 January 2002: Message edited by: nuisance ]

TacKat
01-23-2002, 08:18 PM
If you want to convert into a different base, you end up with digits being M mod x, (M/x) mod x, (M/x^2) mod x, ....

Check out http://www.cut-the-knot.com/recurrence/conversion.html for some examples.

Super Bakemono
01-23-2002, 08:30 PM
Why on earth would you want to change the base? How are you storing the number?

Dru Lee Parsec
01-23-2002, 08:52 PM
Quick quiz:

What's 11 * 11 in base three?

Base four?
Base seven?
Base 10?

Hmm, Is there a pattern here?
;-)

Gnu/Vince
01-23-2002, 11:02 PM
Originally posted by nuisance:
<STRONG>Change of Base Formula


log n1 = log n1 / log b1
b1 b2 b2


b1 = base converting from
n1 = number being converted
b2 = base converting to

what you get on the right side is your solution

Is this what you were looking for?

[ 23 January 2002: Message edited by: nuisance ]</STRONG>

When you put n1, b1 and b2 under, this means division, right?

Gnu/Vince
01-23-2002, 11:03 PM
Originally posted by Super Bakemono:
<STRONG>Why on earth would you want to change the base? How are you storing the number?</STRONG>

Decrypt a string. The two hints are:
"If you count with your fingers, you are off BASE"
"Think FOURward"

TacKat
01-23-2002, 11:24 PM
The numbers under the logs are the bases. In words, the formula is:

The log base1 of n1 is log base2 of n1 divided by log base2 of base1.

TheLinuxDuck
01-24-2002, 06:17 PM
When I started learning python a number of months ago, one of the things I wrote was a base conversion thingie.

Bear in mind that I have no advanced math skillz.. my brain just doesn't seem to comprehend log and that sort of thing.. so I use brute force wherever possible. (^= Here is my attempt:
http://www.codeexamples.org/tld/BaseConversion.py

Here is the output from the examples in the main method at the bottom:

/home/thelinuxduck/python/me/base&gt; ./BaseConversion.py 00101101 base2 is 101101
204 base7 is 204
fa base16 is FA
fa base16 in base 2 is 11111010
fa base16 in base 3 is 100021
fa base16 in base 4 is 3322
fa base16 in base 5 is 2000
fa base16 in base 6 is 1054
fa base16 in base 7 is 505
fa base16 in base 8 is 372
fa base16 in base 9 is 307
fa base16 in base 10 is 250
fa base16 in base 11 is 208
fa base16 in base 12 is 18A
fa base16 in base 13 is 163
fa base16 in base 14 is 13C
fa base16 in base 15 is 11A
fa base16 in base 16 is FA


The code isn't very pretty, but I'm only a duck...

nuisance
01-24-2002, 09:27 PM
Another way of saying :


log b = c
a


is 'c' is the power you have to raise 'a' to get 'b'.


So a^c = b (a to the cth power equals b)

Dru Lee Parsec
01-28-2002, 07:59 PM
Quick quiz:
What's 11 * 11 in base three?


121


Base four?


121


Base seven?


121


Base 10?


121


Hmm, Is there a pattern here?


It seems so. In fact, a little thought will show that 11*11=121 in every base higher than base 2 (you must have the characters 1 and 2 in your base. Base two only has 1 and 0)

Oh, and in case nobody else has thought to say it:

All your base are belong to us

takshaka
01-29-2002, 10:53 PM
Originally posted by Dru Lee Parsec:
All your base are belong to us

That was uncalled for :D

btw--nuisance, nice to see another fine resident of the Palmetto State.