Re: make a program using C,C++
- From: David Bolt <blacklist-me@xxxxxxxxxx>
- Date: Tue, 17 Jan 2006 15:48:48 +0000
On Tue, 17 Jan 2006, pete <pfiland@xxxxxxxxxxxxxx> wrote:-
David Bolt wrote:
^^^^^^^^^^^^^Even though it's looks like this is the solution to a homework question, is there any reason for not doing it this way:
printf("\nBinary: "); for(counter=(sizeof(int)*8);counter>=0;--counter) { temp = 1 << (counter); printf("%d", (number & temp) ? 1 : 0); }
What is (1 << (sizeof(int)*8)) supposed to be?
gives the number of bits in an int and left-shifts 1 that number of times.
I suppose that I should have used:
for(counter=(sizeof(int)*CHAR_BIT);counter>=0;--counter)
^^^^^^^^^
However, I'm guessing that you missed the above, which would mean that mean you missed that for the first run through the loop:
temp = 1 << (counter);
would be the equivalent of:
temp = 1 << ((sizeof(int)*8)-1)
Regards, David Bolt
-- Member of Team Acorn checking nodes at 50 Mnodes/s: http://www.distributed.net/ AMD1800 1Gb WinXP/SUSE 9.3 | AMD2400 256Mb SuSE 9.0 | A3010 4Mb RISCOS 3.11 AMD2400(32) 768Mb SUSE 10.0 | RPC600 129Mb RISCOS 3.6 | Falcon 14Mb TOS 4.02 AMD2600(64) 512Mb SUSE 10.0 | A4000 4Mb RISCOS 3.11 | STE 4Mb TOS 1.62 .
- Follow-Ups:
- Re: make a program using C,C++
- From: Flash Gordon
- Re: make a program using C,C++
- References:
- make a program using C,C++
- From: mavic
- Re: make a program using C,C++
- From: Arne Demmers
- Re: make a program using C,C++
- From: mavic
- Re: make a program using C,C++
- From: Arne Demmers
- Re: make a program using C,C++
- From: David Bolt
- Re: make a program using C,C++
- From: pete
- make a program using C,C++
- Prev by Date: Re: why return causes an Illegal syntax??
- Next by Date: unions & structs...
- Previous by thread: Re: make a program using C,C++
- Next by thread: Re: make a program using C,C++
- Index(es):
Relevant Pages
|