home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!destroyer!sol.ctr.columbia.edu!eff!world!tombaker
- From: tombaker@world.std.com (Tom A Baker)
- Subject: Re: (SOLUTION) How to print an integer as binary?
- Message-ID: <BxAn1s.32t@world.std.com>
- Organization: Me, at The World Public Access UNIX, Brookline, MA
- References: <1992Nov4.180622.6568@csd.uwe.ac.uk>
- Date: Fri, 6 Nov 1992 12:08:15 GMT
- Lines: 30
-
- In article <1992Nov4.180622.6568@csd.uwe.ac.uk> th2_oate@csd.uwe.ac.uk (Tom Oates) writes:
-
- TO> Assuming that:-
- TO>
- TO> int i = 203;
- TO>
- TO> How do I display 'i' as 11001011?
-
- I am amazed at the timing, a coincidence ... I've just completed a
- package to do this, and used it on a project on Forward Error
- Correcting Codes. It provides for constants (either "11001011",
- "b11001011", or "0b11001011" (I prefer the last)), and converting
- to and from strings to and from integers, and to floats (1-1/2
- becomes "1.1" in binary).
-
- Once I put it together this weekend, I'll be glad to mail it to
- requestors, and may pop it onto comp(or *).sources .
-
- Incidentally, the string routine you specifically asked about uses
- the algorithm:
-
- 1) Convert to octal string.
-
- 2) Convert THAT to binary characters.
-
- 3) Use a "while()" loop to get rid of the leading zeros.
-
- tombaker@world.std.com
-
-
-