Re: [OT] Re: Long number base conversion

On 11/27/2010 3:44 PM, BartC wrote:

"Eric Sosman" <esosman@xxxxxxxxxxxxxxxxxxxx> wrote in message
If you know you want to convert the result to decimal (and perhaps
that you don't want to do much else with it), one thing you can do is
handle the trailing zeroes specially. As you're plowing along building
up 1 * 2 * 3 * ... you can remove all the 2's and 5's from each new
factor and count how many you've removed. Then at the end you'll have

You mean that in 11! * 12, the 12 becomes 6, and I add one to the number
of two's?

Almost. The 12 becomes 3 and you add *two* to the number of twos.

What about *25 which becomes *5, do I apply the rule again to get *1?

Yes. And when you get to *300 you accumulate two twos and two
fives and wind up with *3.

(I've just tried this, and unless I made a mistake (which is quite
likely), I found it difficult to measure the difference on 100000!, and
that's without doing the adjustments at the end.)

I neglected to say so, but I assumed you'd do the "casting out"
of twos and fives in ordinary integer arithmetic, before moving into
the big-number realm. Also, an operation to multiply a big-number by
an ordinary integer (rather than by a big-number whose value happens
to be "small") would probably be worth while.

Eric Sosman