Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: long integer to hexadecimal conversion

by Joost (Canon)
on Oct 01, 2009 at 12:38 UTC ( [id://798629]=note: print w/replies, xml ) Need Help??


in reply to Re^2: long integer to hexadecimal conversion
in thread long integer to hexadecimal conversion

Much simpler:
use bigint; my $n = 123456789123456; print $n->as_hex;
or just
use bigint; print 123456789123456->as_hex

Replies are listed 'Best First'.
Re^4: long integer to hexadecimal conversion
by kikuchiyo (Hermit) on Oct 01, 2009 at 12:58 UTC
    True.

    You'd only need my algorithm if you wanted to express the integer in a base other than 16 (or 8).

    use bigint; my @digits=map chr,(0x30..0x39,0x41..0x5d); my $base = 22; my $n = 123456789123456; my $h; while($n > 0){ $h .= $digits[ $n % $base ]; $n /= $base; } print scalar reverse $h';
    Result is 4E5G93GHBE8.
Re^4: long integer to hexadecimal conversion
by perl_fan (Novice) on Oct 05, 2009 at 07:24 UTC
    Super Duper Cool Thanks Joost

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://798629]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-03-19 10:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found