in reply to bin2dec for big numbers

That's not "bin2dec". That's "bin2number". A common mistake, but a mistake nonetheless.

It's Perl that's doing "number2dec" when the number is being printed for you to read it. But before that, it's not "decimal". It's just a quantity without a number base.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.


update: For those of you that didn't follow my 4am garbled reference... I was talking about the "cookbook" bin2dec, which is misnamed. Yes, the bignum code included in this post is in fact bin-string-to-dec-string. Cool.

Replies are listed 'Best First'.
Re^2: bin2dec for big numbers
by Aristotle (Chancellor) on Jan 18, 2005 at 11:17 UTC

    Well no. He is converting a base-2 string to a base-10 string, explicitly working character by character on strings in both cases. Perl is internally doing the base-10 to base-2^32 and back thing as he works through the base-10 digits, but the algorithm itself is indeed bin2dec.

    Makeshifts last the longest.

Re^2: bin2dec for big numbers
by spurperl (Priest) on Jan 18, 2005 at 11:43 UTC
    I don't understand. Using your language, it must then be number2number, since a perl string of 0s and 1s is no more 'bin' than a string of 0s-9s is a 'dec'.

    IMHO it's a matter of definitions, and on what abstraction level you think about it. I think about a string of 0s and 1s as a binary number in my internal represenation. The same way, I think about a string of 0s - 9s as a decimal string in my internal representation.

    What Perl does for me is just print ASCII characters on the screen.