试试这个:
unsigned long long int N; = 23229877463LL;
NSString* s = [NSString stringWithFormat:@"dec:%qi, hex:%qX",N,N];
NSLog(@"output: %@",s);
output: dec:23229877460, hex:689BCCD400000005
00000005怎么了?在mySQL中,hex(23229877460)= 5689BCCD4。此外,所有其他语言似乎都正确地这样做。一个16位长的十六进制就像4亿(16 ^ 16),对吗?
如何获得objective-c格式化其他语言可以理解的十六进制数?
答案 0 :(得分:3)
将假的;
修复为产生:
unsigned long long int N = 23229877463LL;
NSString* s = [NSString stringWithFormat:@"dec:%qi, hex:%qX",N,N];
NSLog(@"output: %@",s);
代码完全符合预期:
2011-01-09 10:46:16.236 dfjkdfkjfdjkfd[25716:a0f] output: dec:23229877463, hex:5689BCCD7
还有其他问题。您需要发布更多代码。用于编译文件的行也可能有用。
嘻嘻哈哈:
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