Re: NSNumber stringValue not returning correct value
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