Praveena Vittal schreef:
> I am newbie to PERL.
ITYM: Perl.
> I think this is a very simple question to ask.
Well, let's see.
> Is there any way to print a particular bit of a digit after converting
> to binary form.
Why convert anything "to binary" first, if you can use
"$var & (1 << $bitpos)"?
$ echo 200
| perl -nle 'printf "\n b %5d\n-- -----\n", $_;
for $b (0 .. 15)
{ printf "%2d %5s\n",
$b, $_ & ($p = 1 << $b) ? $p : "" }'
$ echo 3276767676
| perl -nle 'printf "\n b %10d\n-- ----------\n", $_;
for $b (0 .. 31)
{ printf "%2d %10s\n",
$b, $_ & ($p = 1 << $b) ? $p : ""}'
For larger integers, look for bigint on CPAN.
--
Affijn, Ruud
"Gewoon is een tijger."
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>