Reputation: 1475
Try this:
unsigned long long int N; = 23229877463LL;
NSString* s = [NSString stringWithFormat:@"dec:%qi, hex:%qX",N,N];
NSLog(@"output: %@",s);
output: dec:23229877460, hex:689BCCD400000005
What's up with the 00000005??? In mySQL, hex(23229877460) = 5689BCCD4. Also, every other language seems to do this correctly. A 16 digit long hex is like 4 gazillion (16^16), right?
How can I get objective-c to format hex numbers that other languages can understand?
Upvotes: 0
Views: 2370
Reputation: 162712
After fixing the spurious ;
to yield:
unsigned long long int N = 23229877463LL;
NSString* s = [NSString stringWithFormat:@"dec:%qi, hex:%qX",N,N];
NSLog(@"output: %@",s);
The code works exactly as expected:
2011-01-09 10:46:16.236 dfjkdfkjfdjkfd[25716:a0f] output: dec:23229877463, hex:5689BCCD7
There is something else wrong. You'll need to post more code. The line used to compile the file would probably be helpful, too.
And for giggles:
unsigned long long int N = 23229877460LL;
NSString* s = [NSString stringWithFormat:@"dec:%qi, hex:%qX",N,N];
2011-01-09 10:49:10.425 dfjkdfkjfdjkfd[25755:a0f] output: dec:23229877460, hex:5689BCCD4
Upvotes: 3