简体   繁体   English

在32位iPhone上处理64位整数

[英]Handling 64 bit integers on a 32 bit iPhone

I would like to handle 64 bit unsigned integers on a iPhone 4s (which of course has a 32 bit ARM 6 processor). 我想在iPhone 4s上处理64位无符号整数 (当然它有32位ARM 6处理器)。

When trying to work with 64 bit unsigned integers, eg Twitter IDs, I have the following problem: 当尝试使用64位无符号整数,例如Twitter ID时,我遇到以下问题:

// Array holding the 64 bit integer IDs of the Tweets in a timeline:
NSArray *Ids =[timelineData valueForKeyPath:@"id"];

// I would like to get the minimum of these IDs:
NSUInteger minId = (NSUInteger) Ids.lastObject;

The array Ids contains the following numbers (= Tweet Ids): 数组Ids包含以下数字(=推文ID):

491621469123018752,
491621468917477377,
491621465544851456,
491621445655867393

However, minId returns the incorrect value of 399999248 (instead of 491621445655867393 ) 但是, minId返回不正确的值399999248 (而不是491621445655867393

How can I find the minimum or the last object in an Array of 64 bit integers on an iPhone 4s? 如何在iPhone 4s上找到64位整数数组中的最小或最后一个对象?

You need to use a type that is always 64 bit instead of NSUInteger . 您需要使用始终为64位而不是NSUInteger You can use uint64_t or unsigned long long . 您可以使用uint64_tunsigned long long You also need to get the integer value out of the NSNumber (arrays can't store C types). 您还需要从NSNumber中获取整数值(数组不能存储C类型)。 to do this you need to call 要做到这一点,你需要打电话

uint64_t minID = [Ids.lastObject longLongValue];

Edit 编辑

Changed to use uint64_t in example code as it has been correctly pointed out this shows your intent better. 更改为在示例代码中使用uint64_t,因为它已被正确指出,这更好地显示了您的意图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM