delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/10/26/01:03:23

From: Jack Klein <jackklein AT spamcop DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Couple of Routine Questions
Message-ID: <jLb3OR2s+WEz6gNFyIypeJA2CwU3@4ax.com>
References: <39f746ba DOT 108918810 AT 192 DOT 168 DOT 0 DOT 111>
X-Newsreader: Forte Agent 1.6/32.525
MIME-Version: 1.0
Lines: 58
Date: Thu, 26 Oct 2000 04:45:20 GMT
NNTP-Posting-Host: 12.75.161.175
X-Complaints-To: abuse AT worldnet DOT att DOT net
X-Trace: bgtnsc07-news.ops.worldnet.att.net 972535520 12.75.161.175 (Thu, 26 Oct 2000 04:45:20 GMT)
NNTP-Posting-Date: Thu, 26 Oct 2000 04:45:20 GMT
Organization: AT&T Worldnet
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

On Wed, 25 Oct 2000 21:13:13 GMT, bothersome AT mindspring DOT com (Nunya
Bidny) wrote in comp.os.msdos.djgpp:

> 
> Hi, I've started working on a small project that I want to do in C just to help
> me learn the constructs of the language.  I'm in need of a couple of basic
> building blocks to use in the rest of the program.  Here is what I need:
> 
> main(void) {
> 
>    int x;
> 
>    x = 42; 
>    y = "01110110101"; /* could be any length
>                          up to 32 bits    */
> 
>    printf(" %s ", Int2Bin(x));
>    printf(" %d ", Bin2Int(y));
> 
> }
> 
> char Int2Bin(int x) {
> 
>    /* please put me some efficient code here
>       so that the returned string will equal
>       the bits as "00101010" for 42.
>       of course some of the values of x might
>       be -33 or -384374 or 583732.
>       (integers are 32 bits wide here) */
> 
> }
> 
> int Bin2Int(char x) {
> 
> 	/* Basically need code to do the reverse
>        of Int2Bin. */
> 
> }
> 
> I know there probably is an easy solution.  I'm going to hit the books tonight
> to try to build my own routing, but I thought the good folks of the internet
> could probably build me a much more elegant looking one.  This (full) project
> will probably be placed onto the internet for other people to see and study.
> Just for it's teaching qualities.
> 
> This is not a home-work project...  I'm 35 and just dabbling in this language.
> 
> My email address is correct... so if you don't want everyone to see your code
> you can email if you want.  But, I thought we were all here to learn.

Go to my web page http://home.att.net/~jackklein/ctips01.html and look
at the two samples for inputting and outputting text string
representation of the binary bits in unsigned char.  Extending it to
larger integral types is left as an exercise for the user.

Jack Klein
-- 
Home: http://jackklein.home.att.net

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019