----Original Message----- From: Dr.Ruud [mailto:[EMAIL PROTECTED] Sent: Friday, April 21, 2006 9:19 AM To: beginners@perl.org Subject: Re: Extracting a bit of a scalar variable
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 : "" }' snip -- Affijn, Ruud ************************************************************** b 200 -- ----- 0 1 2 3 8 4 5 6 64 7 128 8 9 10 11 12 13 14 15 So what does this output tell me in English, that the decimal number 200 is composed of ??? Derek Bellner Smith Unix Systems Engineer Cardinal Health Dublin, Ohio [EMAIL PROTECTED] Working together. For life.(sm) _________________________________________________ This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, please notify the sender immediately and delete the original. Any other use of the email by you is prohibited. Dansk - Deutsch - Espanol - Francais - Italiano - Japanese - Nederlands - Norsk - Portuguese - Svenska: www.cardinalhealth.com/legal/email -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>