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

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!sun-barr!apple!news.oc.com!convex!tchrist
  3. From: Tom Christiansen <tchrist@convex.COM>
  4. Subject: Re: *Another* embarrassingly simple question
  5. Message-ID: <1992Jul23.032422.19442@news.eng.convex.com>
  6. Originator: tchrist@pixel.convex.com
  7. Sender: usenet@news.eng.convex.com (news access account)
  8. Nntp-Posting-Host: pixel.convex.com
  9. Reply-To: tchrist@convex.COM (Tom Christiansen)
  10. Organization: CONVEX Realtime Development, Colorado Springs, CO
  11. References: <21982@venera.isi.edu>
  12. Date: Thu, 23 Jul 1992 03:24:22 GMT
  13. X-Disclaimer: This message was written by a user at CONVEX Computer
  14.               Corp. The opinions expressed are those of the user and
  15.               not necessarily those of CONVEX.
  16. Lines: 17
  17.  
  18. From the keyboard of sondeen@isi.edu (Jeff Sondeen):
  19. :How can I print a number as binary?  What I want is
  20. :    $num = 5;
  21. :    print "%4b", $num;    # but it doesn't give me 0101
  22. :        ^^^
  23. :        wishfull thinking
  24.  
  25. Use:
  26.  
  27.     print unpack('B*', pack('N',$number))
  28.  
  29. --tom
  30. -- 
  31.     Tom Christiansen      tchrist@convex.com      convex!tchrist
  32.  
  33.  
  34.     It's all magic.  :-)        --Larry Wall in <7282@jpl-devvax.JPL.NASA.GOV>
  35.