On Apr 21, 2006, at 20:59, Praveena Vittal wrote:

Is there any way to print a particular bit of a digit after converting to binary form.

That can be easily done with substr y sprintf, this would take the second bit of 7 written in base 2:

  % perl -wle 'print substr sprintf("%b", 7), -2, 1'
  1

That's quite readable, but if efficiency is an issue then pack/unpack might be better, it had to be measured in any case.

-- fxn


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to