### integer value to hex value

by shyam123 (Initiate)
 on Dec 05, 2012 at 10:30 UTC 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

Replies are listed 'Best First'.
Re: integer value to hex value
by AnomalousMonk (Chancellor) 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 blue_cowdawg (Monsignor) 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
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 !!

Create A New User
Node Status?
node history
Node Type: perlquestion [id://1007257]
Approved by marto
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2018-04-25 03:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My travels bear the most uncanny semblance to ...

Results (88 votes). Check out past polls.

Notices?