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 ;)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: String to Hex
by shmem (Chancellor) on May 22, 2007 at 21:14 UTC | |
|
Re^2: String to Hex
by blazar (Canon) on May 22, 2007 at 22:24 UTC | |
by BrowserUk (Patriarch) on May 22, 2007 at 22:40 UTC | |
by GrandFather (Saint) on May 22, 2007 at 23:57 UTC | |
by BrowserUk (Patriarch) on May 23, 2007 at 00:05 UTC |