Won't this output the digits in reverse order?
--Andy
On Nov 9, 2009, at 5:27 AM, Graham Cox <graham....@bigpond.com> wrote:
On 09/11/2009, at 9:01 PM, Ron Fleckner wrote:
void to_binary(int n)
{
int r;
r = n % 2;
if (n >= 2)
to_binary(n / 2);
putchar('0' + r);
return;
}
The above sledgehammer-hammer-ammer-mmer-mer-er is not required to
crack such a nut:
void to_binary( int n )
{
do
putchar(( n & 1 )? '1' : '0');
while( n >>= 1 );
}
--Graham
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/aglee%40mac.com
This email sent to ag...@mac.com
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to arch...@mail-archive.com