in reply to Re^3: Big Int to hex with 5.6
in thread Big Int to hex with 5.6

no. it will run on a large number of machines and i have no possibility to upgrade them all, moreover for a single functionality.

Replies are listed 'Best First'.
Re^5: Big Int to hex with 5.6
by ysth (Canon) on Dec 12, 2004 at 23:36 UTC
    Then I would strongly encourage you to not use the module at all. IIRC, there was an initial attempt to convert the perl4 bigint facilities to a perl5 module that then languished in an incomplete and buggy state for years. Only lately has the module been maintained and improved (and made much faster). To quote the doc you linked to:
    BUGS The current version of this module is a preliminary version of the rea +l thing that is currently (as of perl5.002) under development.
    Seeing that 5.002 in 5.6 should give you a clue that nobody was bothering much about it for a long time.

    OTOH, if the bugs aren't biting you, they aren't biting you.

      Arg ! But i need a way to do it ! Here's a nice function i found that converts from hex to dec using only one BigInt.
      #!perl use strict; use Math::BigInt; sub HeX { my $n = shift; $n = '0' x (4 - (length($n) % 4)) . $n; my $m = Math::BigInt->new(0); while (my $o = substr($n, 0, 4, '')){ $m = $m * 65536 + hex $o; } $m; }
      I'm trying to find a way to do something similar but from dec to hex . Maybe you have an idea ?
        This works for me on cygwin perl 5.6.2 (Math::BigInt version 0.01):
        #!/usr/local/bin/perl5.6.2 use Math::BigInt; BEGIN { if (!exists &Math::BigInt::as_hex) { *Math::BigInt::as_hex = sub { my $i = shift; my $hex = ''; do { my $mod = $i % 16; $hex .= sprintf("%x", $mod); } while $i = $i / 16; scalar reverse $hex; } } } $z = new Math::BigInt("1234567890"x 3); print $z->as_hex();
        Slight variations failed completely, though :)

        This is the as_hex() function from Activestate 5.8.0 (which is actually different from the one currently in CPAN):