• 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: NSNumber stringValue not returning correct value
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSNumber stringValue not returning correct value


  • Subject: Re: NSNumber stringValue not returning correct value
  • From: Nick Zitzmann <email@hidden>
  • Date: Fri, 21 Jan 2005 19:46:16 -0700


On Jan 21, 2005, at 5:09 PM, Ken Tozier wrote:

NSNumber *aNum = [[NSNumber alloc] initWithUnsignedLong: 0xFFFFFFFF];
[...]
Which prints

aNum = -1
[...]
So why isn't it returning 255 instead of -1?

0xFFFFFFFF is 2^32-1, not 255. Hexadecimal is base-16, so each character represents 4 bits.


Anyone point out what I'm doing wrong?

IIRC, you're not doing anything wrong. From what I've learned through previous discussions on this list, NSNumber does not properly support unsigned decimal values, so the result you got doesn't surprise me too much. So if you absolutely need to store a 32-bit value in an NSNumber for some reason, at this time I think you'll need to resort to using a long long instead and manually check for overflows...


Nick Zitzmann
<http://www.chronosnet.com/>

_______________________________________________
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


References: 
 >NSNumber stringValue not returning correct value (From: Ken Tozier <email@hidden>)

  • Prev by Date: Re: [Moderator] Re: Authorization without permanent setuid on helper
  • Next by Date: Re: Authorization without permanent setuid on helper
  • Previous by thread: NSNumber stringValue not returning correct value
  • Next by thread: XML and encoding
  • Index(es):
    • Date
    • Thread