ZlR has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I need to convert a bigint number into an hexadecimal representation.

Only i'm under win32 perl 5.6 and there is no internal function to do this.

Does anyone know how to do it ? thanks a lot !

Replies are listed 'Best First'.
Re: Big Int to hex with 5.6
by stajich (Chaplain) on Dec 12, 2004 at 20:16 UTC
    If you are using the Math::BigInt module call $x->as_hex(); as it says in the module documentation.
      Well apparently not with win32 5.6 :

      #!perl use strict ; use warnings; my $bignum = Math::BigInt->new('1111111111111111111111111'); $bignum->as_hex(); print $bignum ;

      gives :

      Can't locate object method "new" via package "Math::BigInt" (perhaps y +ou forgot to load "Math::BigInt"?) at t.pl line 4.

      as_hex is not in the doc, either, but i indeed saw it with 5.8

        There's an important clue in the error message: you need to use Math::Bigint; (or use bigint;). But if you aren't already doing that, what do you mean by a "bigint number"?

        Oh, I see; you perhaps are using the ancient decrepit perl4-ish bigint.pl; you are strongly advised to install a new version of Math::BigInt (which I believe includes a bigint.pm module also) which has scads of bug fixes and use it instead.

        You also should be doing print $bignum->as_hex();; just calling it in void context doesn't do anything.

        So you are using an older version of the module, you should upgrade the module if you want this functionality.
        err, sorry !

        Here it is :

        #!perl use strict ; use warnings; use Math::BigInt ; my $bignum = Math::BigInt->new('1111111111111111111111111'); $bignum->as_hex(); print $bignum ;
        gives
        Can't locate object method "as_hex" via package "Math::BigInt" (perhap +s you forgot to load "Math::BigInt"?) at t.pl line 6.