List Info

Thread: Re: Ascii to hexavalue and decimal




Re: Ascii to hexavalue and decimal
country flaguser name
United States
2007-09-17 06:31:10

Try this code:

#!/usr/bin/perl

use warnings;
use strict;

my $char = '(c)';
my $decval = ord $char;
my $hexval = sprintf("%x";, $decval);

print "$char in hex is $hexval and in dec is $decval";

HTH.

On 9/17/07, pank_chat245 < pankaj.chaturvedi%40aptaracorp.com">pankaj.chaturvediaptaracorp.com> wrote:
&gt;
> Hi everybody,
>
&gt; Can somebody throw some light why my code is not working.
>
>; All I am trying to covert ascii character in to their corresponding hexa
>; value and to decimal
> values too.
>;
> I am working on Mac OS X
>
> #!/usr/bin/perl
>;
> $char = (c);
>; $hexval = sprintf(&quot;%x";, $char);
> $decval = hex($hexval);
>
> print "$char in hex is $hexval and in dec is $decvaln&quot;;
>;
> Thanks for suggestiona.
>
> Pankaj
&gt;
>
>

--
Thiago Nascimento
perl -e '$_="tMM naaCt Feocmama_itpUilucoGa";$_.=$1,print $2 while
s/(..)(.)//;print substr$_,1,1;'
&quot;...just because I don't know the meaning of my art, does not mean it has no
meaning..." S.D.

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
Re: Ascii to hexavalue and decimal
country flaguser name
United States
2007-09-17 06:50:54

Perfect!!! I made few changes in it to get &#x000A9; sort of output.

Thanks again.

On 9/17/07 5:01 PM, "Thiago Nascimento" < nascimenthiago%40gmail.com">nascimenthiagogmail.com> wrote:

>
>
>
>
> Try this code:
&gt;
> #!/usr/bin/perl
>;
> use warnings;
> use strict;
>
> my $char = '(c)';
&gt; my $decval = ord $char;
&gt; my $hexval = sprintf(&quot;%x";, $decval);
>
> print "$char in hex is $hexval and in dec is $decval&quot;;
>
> HTH.
>;
> On 9/17/07, pank_chat245 < pankaj.chaturvedi%40aptaracorp.com">pankaj.chaturvediaptaracorp.com
&gt; <mailto:pankaj.chaturvedi%40aptaracorp.com> > wrote:
&gt;> >
>;> > Hi everybody,
>> >
>;> > Can somebody throw some light why my code is not working.
>> >
>;> > All I am trying to covert ascii character in to their corresponding hexa
>;> > value and to decimal
>> > values too.
>;> >
>;> > I am working on Mac OS X
>&gt; >
>;> > #!/usr/bin/perl
>;> >
>;> > $char = (c);
>;> > $hexval = sprintf(&quot;%x";, $char);
>> > $decval = hex($hexval);
>> >
>;> > print "$char in hex is $hexval and in dec is $decvaln&quot;;
>;> >
>;> > Thanks for suggestiona.
>&gt; >
>;> > Pankaj
&gt;> >
>;> >
>>; >

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
Re: Ascii to hexavalue and decimal
country flaguser name
United States
2007-09-17 10:40:35

>>&gt;>> "Thiago" == Thiago Nascimento < nascimenthiago%40gmail.com">nascimenthiagogmail.com> writes:

Thiago&gt; my $char = '(c)';
Thiago> my $decval = ord $char;

That's not really "decimal". It's just a "number" internally, without a
numeric base. Well, technically, it's represented in IEEE Floating Point, but
you probably don't care about that. The only time it becomes "decimal" is
when it gets printed, where it is sent automatically through "number to
decimal" conversions.

Thiago> my $hexval = sprintf(&quot;%x";, $decval);

So this is a "number to hex" conversion, not a decimal to hex conversion.

Just trying to get the terminology nailed down, because misstating it
at this level can lead to bizarre conclusions.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<; merlyn%40stonehenge.com">merlynstonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

__._,_.___
.

__,_._,___
[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )