Home > Archive > PERL Beginners > July 2007 > hex conversion
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| venkateshwar@hotmail.com 2007-07-19, 3:59 am |
| hello all,
i have a hex value which needs to be checked if a particular bit is
set in that string.
for example, i need to check if 12th bit is set.
i tried doing mask(0x1000) with my input value i receive, so that only
if 12th bit is 1, will the answer be one....but can i do a direct
comparison as in
$mp = $inputhexval & 0x1000;
i m a starter, so i dont know the nuances with perl?
pls help
regards
venkat
| |
| Tom Phoenix 2007-07-19, 3:59 am |
| On 7/18/07, venkateshwar@hotmail.com <venkateshwar@hotmail.com> wrote:
> i have a hex value which needs to be checked if a particular bit is
> set in that string.
You probably want to start with the hex() function, which turns a
string like '01AF' into a number. But there are other ways; if it's an
arbitrarily-long hex string, you could use pack to turn it into a
bitstring.
my $bitstring = pack("H*", '01AF');
> for example, i need to check if 12th bit is set.
That's possible with the vec() function; see perlfunc.
> i tried doing mask(0x1000) with my input value i receive, so that only
> if 12th bit is 1, will the answer be one....but can i do a direct
> comparison as in
>
> $mp = $inputhexval & 0x1000;
What happened when you tried it?
The & operator is documented in the perlop manpage.
Good luck with it!
--Tom Phoenix
Stonehenge Perl Training
|
|
|
|
|