shyam123 has asked for the wisdom of the Perl Monks concerning the following question:


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 (Bishop) 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 <>
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 !!