in reply to Converting an array of bytes into a BigInt - speed considerations

Horner rule for evaluating a polynomial from an array of coefficients:

sub bytearray_to_bigint { my $result = Math::BigInt->new('0'); while (@_) { $result <<= 8; # was *= 256; $result += pop; } $result; }
This algorithm is pretty efficient and needs no data tables kept.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Horner Rule Re: Converting an array of bytes into a BigInt
by BrowserUk (Patriarch) on Jan 24, 2003 at 06:58 UTC

    Methinks maybe Horner used an 8-bit machine and binary rather than stringyfied numbers :^).


    Examine what is said, not who speaks.

    The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.