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