Re: beginner question, NSNumber, NSDecimalAsNumber
Re: beginner question, NSNumber, NSDecimalAsNumber
- Subject: Re: beginner question, NSNumber, NSDecimalAsNumber
- From: Thomas Wetmore <email@hidden>
- Date: Mon, 09 Nov 2009 05:49:38 -0500
The approach found by Ron prints the bits in correct order. The
suggested replacement prints them backwards. Other correct solutions
can be done without recursion, but require a char buffer that must
either be reversed or printed in reverse order.
Tom Wetmore
On Nov 9, 2009, at 5:27 AM, Graham Cox 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 (email@hidden)
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:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden