home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!charon.amdahl.com!pacbell.com!sgiblab!darwin.sura.net!haven.umd.edu!news.umbc.edu!umbc8.umbc.edu!cs202144
- From: cs202144@umbc8.umbc.edu (cs202144)
- Subject: Re: How to print an integer as binary?
- Message-ID: <1992Nov19.171903.19574@umbc3.umbc.edu>
- Sender: newspost@umbc3.umbc.edu (News posting account)
- Organization: University of Maryland, Baltimore County Campus
- References: <1992Nov4.180622.6568@csd.uwe.ac.uk> <1992Nov5.140503.24092@ulysses.att.com> <1992Nov19.131818.2097@umbc3.umbc.edu>
- Date: Thu, 19 Nov 1992 17:19:03 GMT
- Lines: 17
-
- > Assuming that:
- > int i = 203;
- > How do I display 'i' as 11001011?
-
- Someone posted something similar to this and it worked so I cleaned it up and
- made it so you can easily install it into pre-existing code...Here goes:
-
- void dtob (unsigned int i)
- {
- if (i > 1)
- dtob (i >> 1);
- putchar(i & 1 ? '1' : '0');
- }
-
- Nice and short and portable ;)
-
- I may even use it myself since it seems to be working so well so far...
-