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

hi

I got an error said " Integer overflow in hexadecimal number at /acec/nv2am/bin/nokscan line 294.".

The error message happened once i convert hex to int from hextoint function. The function as below. Could somebody help me how to solve to error ?

sub hextoint { my $hex = shift; return sprintf ("%20d", hex($hex)); }

Replies are listed 'Best First'.
Re: Integeer overflow in hexadecimal number
by ikegami (Patriarch) on Mar 11, 2009 at 06:02 UTC

    hex can only handle numbers as big as the integers your Perl can handle. On a Perl with 32-bit integers,

    >perl -le"hex('0xFFFFFFFF')" >perl -le"hex('0x100000000')" Integer overflow in hexadecimal number at -e line 1.

    Math::BigInt's from_hex could be of use. There could be other solutions as well if we were familiar with the bigger picture.

Re: Integer overflow in hexadecimal number
by AnomalousMonk (Archbishop) on Mar 11, 2009 at 07:56 UTC
    bh_perl:

    Also note that had you been using warnings, your warning message would have been more enlightening.

    >perl -w -Mstrict -le "my $n = hex '0x100000000'; print $n; " Integer overflow in hexadecimal number at -e line 1. Hexadecimal number > 0xffffffff non-portable at -e line 1. 4294967296