home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- 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
- From: kpv@ulysses.att.com (Phong Vo)
- Subject: Re: How to print an integer as binary?
- Message-ID: <1992Nov5.140503.24092@ulysses.att.com>
- Date: Thu, 5 Nov 1992 14:05:03 GMT
- References: <1992Nov4.180622.6568@csd.uwe.ac.uk>
- Organization: AT&T Bell Labs
- Lines: 17
-
- In article <1992Nov4.180622.6568@csd.uwe.ac.uk> th2_oate@csd.uwe.ac.uk (Tom Oates) writes:
- >Assuming that:-
- >int i = 203;
- >How do I display 'i' as 11001011?
- >
- If you were using the sfio package instead of stdio, you would do:
- sfprintf(sfstdout,"%..2d\n",i);
- The second dot for %d specifies the base for output which
- can range from 2 to 64. If you also want to display the base,
- you would do
- sfprintf(sfstdout,"%#..2d\n",i);
- to get 2#11001011.
-
- There is a similar pattern for sfscanf() to read data in the same format.
-
- Phong Vo, kpv@ulysses.att.com
- AT&T Bell Labs, 600 Mountain Ave, Murray Hill, NJ07974
-