views:

47

answers:

1

Hello,

I am generating a hash from a NSString, using [myString hash] and the result I get is a negative value.

The Apple's documentation is saying :

  • (NSUInteger)hash

Return Value An unsigned integer that can be used as

Any idea ?

** Edited **

Try this code in your device :

NSString *udidStr =  [[UIDevice currentDevice] uniqueIdentifier];
NSUInteger udid = [udidStr hash];

For some device I get a negative value.

Thanks

+1  A: 

That is probably just a display problem. I bet you are assigning it to a signed integer, or the debugger assumes (as most do) that all integers are signed, since that is more common.

Any number with the first bit set will be "negative", but that doesn't mean the value is incorrect.

Andrew Backer