home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16806 < prev    next >
Encoding:
Internet Message Format  |  1992-11-19  |  884 b 

  1. Path: sparky!uunet!mcsun!news.funet.fi!hydra!klaava!wirzeniu
  2. From: wirzeniu@klaava.Helsinki.FI (Lars Wirzenius)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How to print an integer as binary?
  5. Message-ID: <1992Nov19.182613.9200@klaava.Helsinki.FI>
  6. Date: 19 Nov 92 18:26:13 GMT
  7. References: <1992Nov4.180622.6568@csd.uwe.ac.uk> <1992Nov5.140503.24092@ulysses.att.com> <1992Nov19.131818.2097@umbc3.umbc.edu>
  8. Organization: University of Helsinki
  9. Lines: 17
  10.  
  11. cs202144@umbc8.umbc.edu (cs202144) writes:
  12. [...]
  13. >  putchar(i & 1 | '0');
  14. [...]
  15. >
  16. >Nice and short and portable ;)
  17.  
  18. Hardly portable, since there are no guarantees that setting the lowest
  19. bit of '0' will yield '1'.  I see no reason to not write, for example,
  20.  
  21.     putchar("01"[i & 1]);
  22.  
  23. which is guaranteed to work.
  24.  
  25. --
  26. Lars.Wirzenius@helsinki.fi  (finger wirzeniu@klaava.helsinki.fi)
  27.    MS-DOS, you can't live with it, you can live without it.
  28.