I need to do some arithmetic with large hexadecimal numbers below, but when I try to output I'm getting overflow error messages "Hexadecimal number > 0xffffffff non-portable", messages about not portable, or the maximum 32bit hex value FFFFFFFF. All of which imply that the standard language and output routines only cope with 32 bit values. I need 64bit values and have done a lot of research but found nothing that BOTH enables the arithmetic AND outputs the large number in hex.
my $result = 0x00000200A0000000 +
( ( $id & 0xFFFFF ) * 2 ) + ( ( $id / 0x100000 ) * 0x40000000 );
So, for $id with the following values I should get $result
:
$id = 0, $result = 0x00000200A0000000
$id = 1, $result = 0x00000200A0000002
$id = 2, $result = 0x00000200A0000004
Can anyone help please?
Here is my inconclusive research results, with reasons why:
How can I sum large hexadecimal values in Perl? Vague, answer not definitively precise and no example.
Integer overflow non conclusive
Integer overflow non conclusive
bigint no info about assignment, arithmetic or output
bignum examples not close to my problem.
How can I sprintf a big number in Perl? example given is not enough info for me: doesn't deal with hex assignment or arithmetic.
http://www.perlmonks.org/?node_id=590611 Some examples using Fleximal, mentions to_str to output value of variable but 1) I don't see how the variable was assigned and 2) I get error "Can't call method "to_str" without a package or object reference" when I run my code using it.
String to Hex Example of using Math::BigInt which doesnt work for me - still get overflow error.
Is there a 64-bit hex()? Nearly there - but doesn't deal with outputting the large number in hex, it only talks of decimal.
CPAN Math:Fleximal does the arithmetic but doesn't seem to be any means to actually output the value still in hex
sprintf Doesn't seem to be able to cope with numbers greater than 32bits, get the saturated FFFFFFFF message.