in reply to Re^2: bin2dec for big numbers
in thread bin2dec for big numbers
ObCounter: if you're so concerned about speed, why are you doing numerics in Perl? :-) In case of the reverse join, I don't see why your code is better anyway: you are constantly replacing the string by a character+string.
In any case, it could probably be sped up a little by using string reverse vs list reverse:
sub mul2 { my ( $str, $have_overflow ) = @_; my $ret = reverse join '', map { my $c = $_ * 2 + ( $have_overflow ? 1 : 0 ); $have_overflow = ( $c >= 10 ); ( $c % 10 ); } split //, scalar reverse $str; ( $have_overflow ? 1 : '' ) . $ret; }
Makeshifts last the longest.
|
|---|