Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

integer value to hex value

by shyam123 (Initiate)
on Dec 05, 2012 at 10:30 UTC ( #1007257=perlquestion: print w/ replies, xml ) Need Help??
shyam123 has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have an integer say 66778899 which is the input from user.I want to use this value as hex that is 0x66778899 in my perl script.How to use that?Using sprintf,gives the direct hex value of that.I don't want that to happen.How to go abt it ? Any suggestions please.

thanks sham

Comment on integer value to hex value
Re: integer value to hex value
by AnomalousMonk (Monsignor) on Dec 05, 2012 at 10:49 UTC

    See hex.

    >perl -wMstrict -le "my $i = 100; my $x = hex $i; print $x; printf qq{0x%x \n}, $x; ;; $i = '200'; $x = hex $i; print $x; printf qq{0x%x \n}, $x; " 256 0x100 512 0x200
      Hi Anamolous monk,

      Thanks for the reply.But that was not the one i was looking for.If i have a integer say 55667788, i needed to have this as hex value 0x55667788 and not the hex(55667788).Please share your views on it.

      thanks sham

        my $hexstr=sprintf('%x',55667788);

        -- 
        Ronald Fischer <ynnor@mm.st>
Re: integer value to hex value
by nithins (Sexton) on Dec 05, 2012 at 11:01 UTC
    my $a = 66778899; $a = '0x'.$a; print $a; print hex $a;

    I am not sure but hope this will work. can check it ones, might b ur looking for this !!

Re: integer value to hex value
by blue_cowdawg (Prior) on Dec 05, 2012 at 14:05 UTC

    If you are taking 66778899 and converting it to 0x66778899 why not:

    my $val = "0x" . $val;
    Maybe I'm missing something here....


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (11)
As of 2014-07-29 09:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (212 votes), past polls