Re: Hex to NSString or NSData
Re: Hex to NSString or NSData
- Subject: Re: Hex to NSString or NSData
- From: Gwynne Raskind <email@hidden>
- Date: Sat, 9 May 2009 21:58:32 -0400
On May 9, 2009, at 9:19 PM, Greg Guerin wrote:
char hexCharToNibbleL(char nibble)
Is safer as:
char hexCharToNibbleL(unsigned char nibble)
Otherwise consider what happens if 'char' is signed by default and
the incoming value is 0xB0.
const char lt[255] =
Should be:
const char lt[256]
or:
const char lt[]
and append another:
, 0xFF
Otherwise the input value 0xFF will return an unspecified value.
You know, I knew somewhere in my brain that I was off by one there...
but I generated the lookup table with a quickie PHP script and just
accepted it when the compiler said I had too many initializers.
That'll teach me :).
return (nibble - '0') & 0x0F;
The & 0x0F is superfluous; you've already range-qualified the value
of 'nibble', so subtracting '0' can't possibly yield anything other
than 0-9.
Ditto for other uses of & 0x0F.
True that... I'm just paranoid, I guess.
c = hexCharToNibble(i % 255);
May want to use the & operator instead of %. IIRC, modulus needs
integer division, and may be taking more time than the inlined
hexCharToNibble.
Yeah, but since that was only done as part of a benchmark, it didn't
much matter. It may have skewed the numbers upwards unnecessarily, but
wouldn't have changed their relation to each other since the same
sequence was calculated for all three versions.
-- Gwynne, Daughter of the Code
"This whole world is an asylum for the incurable."
_______________________________________________
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