home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / c / 16020 < prev    next >
Encoding:
Text File  |  1992-11-05  |  1.0 KB  |  28 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!haven.umd.edu!ames!saimiri.primate.wisc.edu!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!att!dptg!ulysses!ulysses.att.com!kpv
  3. From: kpv@ulysses.att.com (Phong Vo)
  4. Subject: Re: How to print an integer as binary?
  5. Message-ID: <1992Nov5.140503.24092@ulysses.att.com>
  6. Date: Thu, 5 Nov 1992 14:05:03 GMT
  7. References: <1992Nov4.180622.6568@csd.uwe.ac.uk>
  8. Organization: AT&T Bell Labs
  9. Lines: 17
  10.  
  11. In article <1992Nov4.180622.6568@csd.uwe.ac.uk> th2_oate@csd.uwe.ac.uk (Tom Oates) writes:
  12. >Assuming that:- 
  13. >int i = 203;
  14. >How do I display 'i' as 11001011?
  15. >
  16. If you were using the sfio package instead of stdio, you would do:
  17.     sfprintf(sfstdout,"%..2d\n",i);
  18. The second dot for %d specifies the base for output which
  19. can range from 2 to 64. If you also want to display the base,
  20. you would do
  21.     sfprintf(sfstdout,"%#..2d\n",i);
  22. to get    2#11001011.
  23.  
  24. There is a similar pattern for sfscanf() to read data in the same format.
  25.   
  26. Phong Vo, kpv@ulysses.att.com
  27. AT&T Bell Labs, 600 Mountain Ave, Murray Hill, NJ07974
  28.