home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / perl / 4888 < prev    next >
Encoding:
Text File  |  1992-07-22  |  1018 b   |  43 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!fmrco!fmrco!asherman
  3. From: asherman@laser.fmrco.com (Aaron Sherman)
  4. Subject: Re: *Another* embarrassingly simple question
  5. In-Reply-To: sondeen@isi.edu's message of 21 Jul 92 16:03:56 GMT
  6. Message-ID: <ASHERMAN.92Jul22172630@laser.fmrco.com>
  7. Sender: news@fmrco.uucp
  8. Reply-To: asherman@fmrco.COM
  9. Organization: I-Kinetics, 19 Bishop-Allen Dr., Cambridge, MA
  10. References: <21982@venera.isi.edu>
  11. Date: Wed, 22 Jul 1992 22:26:30 GMT
  12. Lines: 29
  13.  
  14.  
  15. >>>>> sondeen@isi.edu (Jeff Sondeen) said:
  16.  
  17. sondeen> How can I print a number as binary? 
  18.  
  19. # Int to binary string. Pass a number and the number of bits that
  20. # you want.
  21. sub itobs
  22. {
  23.     local($num,$bits) = @_;
  24.     local($i,$binstr);
  25.  
  26.     for($i=0;$i<$bits;$i++)
  27.     {
  28.         substr($binstr,0,0) = ($n & 1);
  29.         $num >>= 1;
  30.     }
  31.     $binstr;
  32. }
  33.  
  34.  
  35.  
  36.             -AJS
  37.  
  38. --
  39. --------
  40. Disclaimer: I am solely responsible for the content of this message.
  41. The views expressed here may not be the views of I-Kinetics, Fidelity,
  42. any of the Fidelity-owned corporations or my mother.
  43.