home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16798 < prev    next >
Encoding:
Text File  |  1992-11-19  |  1002 b   |  29 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!darwin.sura.net!haven.umd.edu!news.umbc.edu!umbc8.umbc.edu!cs202144
  3. From: cs202144@umbc8.umbc.edu (cs202144)
  4. Subject: Re: How to print an integer as binary?
  5. Message-ID: <1992Nov19.171903.19574@umbc3.umbc.edu>
  6. Sender: newspost@umbc3.umbc.edu (News posting account)
  7. Organization: University of Maryland, Baltimore County Campus
  8. References: <1992Nov4.180622.6568@csd.uwe.ac.uk> <1992Nov5.140503.24092@ulysses.att.com> <1992Nov19.131818.2097@umbc3.umbc.edu>
  9. Date: Thu, 19 Nov 1992 17:19:03 GMT
  10. Lines: 17
  11.  
  12. > Assuming that:
  13. > int i = 203;
  14. > How do I display 'i' as 11001011?
  15.  
  16. Someone posted something similar to this and it worked so I cleaned it up and
  17. made it so you can easily install it into pre-existing code...Here goes:
  18.  
  19. void dtob (unsigned int i)
  20. {
  21.   if (i > 1)
  22.      dtob (i >> 1);
  23.   putchar(i & 1 ? '1' : '0');
  24. }
  25.  
  26. Nice and short and portable ;)
  27.  
  28. I may even use it myself since it seems to be working so well so far...
  29.