home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!rutgers!mcdhup!src4src!wozzle!alane
- From: alane@wozzle.linet.org (J. Alan Eldridge)
- Newsgroups: comp.lang.c
- Subject: Re: Unsigned Char -> 00100110
- Message-ID: <06eqVB5w165w@wozzle.linet.org>
- Date: 13 Dec 92 17:45:20 GMT
- References: <723621396snx@sound.demon.co.uk>
- Organization: Disorganization
- Lines: 26
-
- rob@sound.demon.co.uk (Robert J Barth) writes:
-
- > OK, so I'm lazy...
- > How do I convert an unsigned char into it's 8 bits ?
- > I want to end up with an output of e.g. 00101101
-
- void OutBin(FILE *pf, unsigned char uc)
- {
- int i;
- char sz[ 9 ];
-
- sz[ 8 ] = 0;
-
- for (i = 7; i >= 0; i--) {
- sz[ i ] = '0' + (uc & 1);
- uc = uc >> 1;
- }
-
- fprintf(pf, "%s", sz);
- }
-
- Since this took me less than one minute to write, yeah, you are lazy.
- But I hope it helps you out, anyway.
-
- alane@wozzle.linet.org (J. Alan Eldridge)
- Fido: The University of Walamaloo 1:272/38.473
-