Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: long integer to hexadecimal conversion

by kikuchiyo (Monk)
on Oct 01, 2009 at 10:58 UTC ( #798604=note: print w/ replies, xml ) Need Help??


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

I wanted to say the same thing, but I'm late, I guess:

use bigint; my $n = 123456789123456; my ($h, $d); while ($n > 0) { $d = $n % 16; $n /= 16; $h .= sprintf "%x",$d; } print scalar reverse $h;


Comment on Re^2: long integer to hexadecimal conversion
Download Code
Re^3: long integer to hexadecimal conversion
by Joost (Canon) on Oct 01, 2009 at 12:38 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.
      Super Duper Cool Thanks Joost
Re^3: long integer to hexadecimal conversion
by perl_fan (Novice) on Oct 05, 2009 at 07:29 UTC
    couldn't have been easier than this. Thanks kikuchiyo, you saved my day

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (11)
As of 2015-07-07 12:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls