http://www.perlmonks.org?node_id=616872


in reply to String to Hex

The problem is that the number is too big to be represented as a 32 bit integer and your Perl has been compiled to use 32 bit integers.

For positive integers you can use:

use strict; use warnings; use bigint; my $num = 24600988483; my @parts; while ($num) { unshift @parts, $num & 0xFFFFFFFF; $num /= 0x100000000; } printf "%x", $_ for @parts;

Prints:

5ba554b43

Update: jettero's solution is much cleaner!

Update: Unstruck on advice ;)


DWIM is Perl's answer to Gödel