Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Converting Hexadecimal to Decimal notation and vice-versa

by stonecolddevin (Vicar)
on Oct 17, 2009 at 21:51 UTC ( #801809=note: print w/ replies, xml ) Need Help??


in reply to Converting Hexadecimal to Decimal notation and vice-versa

I think pack could take care of this as well.

UPDATE: Here's an example1:

$int = unpack("N", pack("H8", substr("0" x 8 . "DEADBEEF", -8)));
$dec = sprintf("%d", $int);

Where DEADBEEF is your hex number.

1http://perl.active-venture.com/pod/perlfaq4-datanumber.html

mtfnpy


Comment on Re: Converting Hexadecimal to Decimal notation and vice-versa
Select or Download Code
Re^2: Converting Hexadecimal to Decimal notation and vice-versa
by AnomalousMonk (Abbot) on Oct 18, 2009 at 11:53 UTC
    But how does this apply to the big integers of the OP?
    >perl -wMstrict -le "my $int = unpack('N', pack('H8', '102030405060708090a0b0c0d0e0f')); my $dec = sprintf('%d', $int); print $dec; " 270544960

      Specify a different template for sprintf?

      mtfnpy

        Can you give an example?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (12)
As of 2015-07-02 05:47 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 (29 votes), past polls