如何提取64位有符号整数

如何提取64位有符号整数

本文介绍了如何提取64位有符号整数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我询问一个NSDictionary的一个值。因为我也有问题,我打印的对象。它让我看到以下内容:

<的CFString 0x5d33630 [0x26af380]> {内容=myDictionaryItem} =< CFNumber 0x5d58940 [0x26af380]> {值= 1286301600,类型= kCFNumberSInt64Type}

所以它的类型为符号的64位整数。于是,我就提取这样的值

 的NSString * MyString的= [NSString的stringWithFormat:@%气,[myDictionary objectForKey:@myDictionaryItem]];
 

这给了我一个值,但该值不是一个在字典中。

我也试过这种

 长长my64bitsignedIntegerValue =(久长)[myDictionary objectForKey:@myDictionaryItem];
 

但我得到的警告从指针强制转换为不同大小的整。这并不工作,因为 stringWithFormat 的返回类型 ID 的值。我发现这个post其中, ID 的类型是 UInt32的。而且有符号的64位整数是不是32位无符号整数,所以我得到这样的警告。如果我忽略警告,该值仍然是错误的。

我想有值为例如1286301600.一个有符号整数(-2.147.483.648到2.147.483.647)应该做我想要的东西。我不明白为什么可可正试图使一个64位有符号整数。

我怎么能提取词典的64位有符号整数,并把它作为一个变量?

解决方案

  [myDictionary objectForKey:@myDictionaryItem]
 

返回对象(我想 - NSNumber的),而不是一个标量数量。如果它确实是一个NSNumber的对象,那么你可以使用下面的功能之一从它那里得到一个数字:

  -intValue
-longValue
-longLongValue
 

下面的行必须产生正确的字符串,从您的号码:

 的NSString * MyString的= [NSString的stringWithFormat:@%气,[[myDictionary objectForKey:@myDictionaryItem]的intValue];
 

I'm querying a NSDictionary for a value. Because I got problems I printed the object. It shows me the following:

<CFString 0x5d33630 [0x26af380]>{contents = "myDictionaryItem"} = <CFNumber 0x5d58940 [0x26af380]>{value = +1286301600, type = kCFNumberSInt64Type}

So it is of type signed 64 bit integer. So I tried to extract the value like this

NSString *myString = [NSString stringWithFormat:@"%qi", [myDictionary objectForKey:@"myDictionaryItem"]];

That gives me a value but the value is not the one in the dictionary.

I also tried this

long long my64bitsignedIntegerValue = (long long)[myDictionary objectForKey:@"myDictionaryItem"];

but I get the warning Cast from pointer to integer of different size. That doesn't work because stringWithFormat is returning a value of type id. I found this post where id is of type UInt32. And a signed 64 bit integer is not unsigned 32 bit integer, so I get this warning. If I ignore the warning, the value is still wrong.

The value I would like to have is e.g. 1286301600. A signed integer (−2.147.483.648 to 2.147.483.647) should do the thing I want. I don't understand why Cocoa is trying to make a 64 bit signed Integer.

How can I extract the 64 bit signed integer of the dictionary and use it as a variable?

解决方案
[myDictionary objectForKey:@"myDictionaryItem"]

Returns object (I suppose - NSNumber), not a scalar number. If it is really a NSNUmber object then you can get a number from it using one of the following functions:

-intValue
-longValue
-longLongValue

The following line must produce correct string from your number:

NSString *myString = [NSString stringWithFormat:@"%qi", [[myDictionary objectForKey:@"myDictionaryItem"] intValue]];

这篇关于如何提取64位有符号整数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 15:32