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

Hi Monks How to convert this hex number 9DBE062CB1F34287 into decimal thanks Sid

Replies are listed 'Best First'.
Re: to convert 16 dig hex to dec
by GrandFather (Saint) on Sep 01, 2005 at 10:47 UTC

    Use BigInt:

    use Math::BigInt; my $x = Math::BigInt->new ('0x9DBE062CB1F34287'); print $x; Output: 11366529298563547783

    Perl is Huffman encoded by design.
Re: to convert 16 dig hex to dec
by haoess (Curate) on Sep 01, 2005 at 10:15 UTC
    print hex $value;

    Update: Nevermind this throws a warning:

    Integer overflow in hexadecimal number

    A way without warnings:

    perl -Mbigint -wle 'print 0x9DBE062CB1F34287'

    Please, please have a look at the documentation search engine.

    -- Frank

      perl -Mbigint -wle 'print 0x9DBE062CB1F34287'
      Shouldn't that be:
      perl -MMath::Bigint -wle 'print 0x9DBE062CB1F34287'
      or is there some new namespace I'm not aware of?

      Update: I didn't look carefully enough. And I was cross-pollinated with:

      perl -MMath::Bigint -wle 'print Math::BigInt->new(q/0x9DBE062CB1F34287 +/)'

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of

        Try it.

        And read "perldoc bigint"
      I am getting an overflow error Integer overflow in hexadecimal number at hextodec.pl line 8. This is the output 1.13665292985635e+019 I need the output as not in exponential notation but string and I have tried
      $dec = hex $hex; printf "%s", $dec;