in reply to Extra Long HEX to Decimal Converion Issue on Select Platforms

To clarify:

In the first place, the conversions given are incorrect. According to the Calculator app that comes with Windows Vista, A100 0000 (hexadecimal) is 2,701,131,776 (decimal). Conversely, 270,113,177,609,606,898 (decimal), which the OP was expecting, is actually 3BF A281 0092 96F2 (hexadecimal).

Next, sprintf("%u", 0x3BFA281009296F2) gives the correct answer on a 64int perl build, but on a 32int build it results in:

Integer overflow in hexadecimal number at ...

Yet even on a 64int build, which handles the command without overflow, use warnings produces:

Hexadecimal number > 0xffffffff non-portable at ...

All of which is a good indication that the OP’s idea to use Math::BigInt was the correct one.

But Math::BigInt is a class, so its ‘numbers’ are actually objects, which should be operated-on by methods. So:

#! perl use strict; use warnings; use Math::BigInt; my $n = Math::BigInt->new('0x3BFA281009296F2'); print $n->as_hex(), ' = ', $n->bstr(), "\n";

Output:

0x3bfa281009296f2 = 270113177609606898

which is portable and robust.

Athanasius <°(((><contra mundum

Replies are listed 'Best First'.
Re^2: Extra Long HEX to Decimal Converion Issue on Select Platforms
by awohld (Hermit) on Jul 15, 2012 at 17:33 UTC
    Okay, so what I ended up doing was:
    my $n = Math::BigInt->new('0x3BFA281009296F2'); my $manufacturer = sprintf("%010s", $n->bstr );
    I uploaded the revised module and hopefully this time it passes on all systems.

    Thanks for the help!

      Curiously, this works, too:

      my $n = Math::BigInt->new('0x3BFA281009296F2'); my $manufacturer = sprintf "%010s", $n;

      So the temp variable $n can be eliminated:

      my $manufacturer = sprintf "%010s", Math::BigInt->new('0x3BFA281009296F2');

      I didn't test this on multiple platforms. I'm only pointing it out because I noticed an allusion to it in the Math::BigInt documentation.

      Jim