Den tisdag 7 april 2015 kl. 14:27:36 UTC+2 skrev Ben Bacarisse:
> jonas.thornvall@gmail.com writes:
>
> > I want todo faster baseconversion for very big bases like base 1 000
> > 000, so instead of adding up digits i search it.
>
> The size of the base is immaterial, provided that it is in the range for
> which arithmetic operations are exact. 1,000,000 is well within that
> range.
>
> <snip>
> > <SCRIPT LANGUAGE="Javascript">
> > //CONVERT A DECIMAL NUMBER INTO ANYBASE
> > function newbase(decNumber,base){
>
> Your terms are wrong, and I don't think this is just a trivial detail --
> I think maybe it points to something you've misunderstood. The value in
> "decNumber" is not decimal -- it's just a number.
No you are wrong, the input is an integer and that is a number encoded in base 10, there is no such thing as just a number.
Internally it is
> represented in a very well-defined format that uses binary for both a
> fraction and an exponent, but you don't need to care about that.
>You
> just want to do arithmetic on it. (Maybe one day you will write a
> routine like this that takes a bignum in base X and converts it to
> bignum in base Y, but for the moment, you don't seem to be doing that at
> all.)
I will do very large base arithmetic once i changed the algorithms operations to use bignumb multiplication, division, add and subtraction.
> Anyway, the algorithm for representing a number in base B is the same
> whatever the base is: the least significant digit is obtained by using
> the remainder operation (%) and you can move on to the next one by
> dividing the number by the base. I think you know this already.
That is not base 8 it is base 256, the algorithm convert decimals into any base even into binary base, although not binary they are decimal values encoded into base 2.
You can try whatever base, and the encoding is correct.
I aim to replace the slow add when dealing with real big bases with a search.
> <snip>
> --
> Ben.