Re: Radix Cocoa Class: Int Binary Value to Char String Using Primitive Operators
Re: Radix Cocoa Class: Int Binary Value to Char String Using Primitive Operators
- Subject: Re: Radix Cocoa Class: Int Binary Value to Char String Using Primitive Operators
- From: John Stiles <email@hidden>
- Date: Fri, 6 Jan 2006 10:57:11 -0800
On Jan 6, 2006, at 10:36 AM, Jordan Evans wrote:
Camillo wrote:
|#define BUF_SIZE 100
|char digits[] = "0123456789ABCDEF"; /* add more
digits if you need a
|radix > 16 */
|char buf[BUF_SIZE];
|char *p = buf + BUF_SIZE;
|
|*--p = 0;
|if (n == 0) *--p = digits[0];
|else while (n) {
| *--p = digits[n % radix];
| n /= radix;
|}
This works great, with a couple of smalls fixes. But,
I didn't want to use anything with mod or division.
Again I'm looking for a way to write this by only
using these operators: shift, is equal, is not equal,
addition, subtraction, and the bitwise operators: & |
^
If no one here knows, I'll probably just put in your
idea so I can move on and think about it later. This
this stuff is interesting to me, I'd really like to
know how the search is done using more primitive operators.
Is this for a homework assignment?
Normally there is no reason to tie one hand behind your back like
this. The basic algorithm is going to rely on some form of division
unless you devise something really esoteric. This isn't an Atari
2600... division isn't "slow." (Yes, it's slower than multiplication,
but it's a difference of nanoseconds.)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden