Re: Hex to NSString or NSData
Re: Hex to NSString or NSData
- Subject: Re: Hex to NSString or NSData
- From: Greg Guerin <email@hidden>
- Date: Sat, 9 May 2009 18:19:15 -0700
Gwynne Raskind 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.
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.
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.
These are all nits, although the first two can lead to subtle
malfunctions. The others are mere pointless optimizations which I'm
too lazy to try for myself.
-- GG
_______________________________________________
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