I want to write a perl script to parse text files with a lot of 64-bit integers in it. All integers are written in hex.
I need to
- Read hexes from input
- Compare 64-bit ints (
<
,=
,>
) - Subtract 64-bit ints
- Output 64-bit hexes
I need to use 32-bit perl and I can't use any CPAN/external module (the script must be portable).
PS my perl is 5.8 (and this is minimal version which will be used for the script)
PPS bignum/ bigint errors:
$ perl -e 'use bignum; $_=hex("0x0000123412345678")'
Integer overflow in hexadecimal number at -e line 1.
$ perl -e 'use bigint; $_=hex("0x0000123412345678")'
Integer overflow in hexadecimal number at -e line 1.
PPPS: no from_hex
here.
$ perl -e 'use Math::BigInt; $_=Math::BigInt->from_hex("0x0000123412345678");'
Can't locate object method "from_hex" via package "Math::BigInt" at -e line 1.
And no qw/hex/
:
$ perl -e 'use bigint qw/hex/; $_=hex("0x0000123412345678")'
unknown option hex at /usr/lib/perl5/5.8/bigint.pm line...
PPPPS: but new() works:
$ perl -e 'use Math::BigInt; $_=Math::BigInt->new("0x0000123412345678"); print $_->as_hex(),"\n";'
0x123412345678