• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Hex to NSString or NSData
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Hex to NSString or NSData
      • From: Gwynne Raskind <email@hidden>
  • Prev by Date: Re: Hex to NSString or NSData
  • Next by Date: Re: Hex to NSString or NSData
  • Previous by thread: Re: Hex to NSString or NSData
  • Next by thread: Re: Hex to NSString or NSData
  • Index(es):
    • Date
    • Thread