views:

192

answers:

2

Hello, I want to get the unsigned long value of a NSNumber. I don´t know why, but it doesn't work. Here is what I did:

NSString * stern = [idd objectAtIndex:indexPath.row]; // get a String with Number from a NSArray
NSNumberFormatter * lols = [[NSNumberFormatter alloc] init];
NSNumber * iddd = [lols numberFromString:stern];
NSLog(@"%@", iddd); // I get the right number: 8084143463
unsigned long fooo = [iddd unsignedLongValue];
NSLog(@"%lu", fooo); // I get the wrong number: 3789176167
[twitterEngine deleteUpdate:fooo];
+3  A: 

Your value is larger than the maximum value an unsigned long can hold (2^32 - 1 == 4,294,967,295) in 32-bit mode.

Ole Begemann
+8  A: 
8084143463 == 0x1e1da3d67
3789176167 == 0x0e1da3d67

The size of a long on a 64bit system is 8 bytes. The size of a long on a 32bit system (like the iPhone) is 4 bytes. You need to use a long long on an iPhone to store that value.

Matt B.
That sounds logisch, thanks for the answer. But I tried it with long long fooo = [iddd longLongValue]; and foo is again 3789176167
Flocked
You'll also need to use the format specifier of `%llu`.
Matt B.
Ah now it works. Just forgot to write %llu in NSLog. Thanks!
Flocked