java - Java 中 Objective C 的 longLongvalue?

标签 java android objective-c

如何在 Java 中转换此 Objective C 代码?

NSMutableString * thisPart = [[NSMutableString alloc] init];
UInt64 intVal = (UInt64)[thisPart longLongValue];
if (!intVal) { isBad = YES; break; }

我一直在网上搜索,但没有在网上找到任何有用的信息。

如果我有:

UInt32 _tmpPacket_packetId;
_tmpPacket_packetId = (UInt32)intVal;  // UInt64 intVal = (UInt64)[thisPart longLongValue];

我可以这样做吗:

BigInteger tmpPacket_packetId = intVal;

实际上正确的问题是:为了获得与在 Objective C 中完成的相同的事情,这样做是否正确?

最佳答案

我假设您不关心 NSMutableString 位,它可能类似于 StringBuilder/StringBuffer 类。 UInt64 似乎是 64 位无符号整数?然后你可以使用 BigInteger(String) 提供的 String 构造函数

StringBuilder thisPart = new StringBuilder("12345678901234567890");
try {
    BigInteger intVal = new BigInteger(thisPart.toString());
} catch (NumberFormatException e) {
    System.out.println("Bad value");
    isBad = true;
    break; // or return or what have you
}

关于java - Java 中 Objective C 的 longLongvalue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7204306/

相关文章:

java - 删除方法二叉搜索树

Javafx,将 TableView 与数据库结合使用

java - 获取 JSONObject 作为数组,以帮助将其转换为 CSV

java - 重新启动应用程序后保存的图像消失

android - 在 Android 中使用 GLU ES

android - 三星 Galaxy Note 上奇怪的内存问题

ios - 在水龙头上删除 UITableViewCell

ios - Objective-C 从 block 中获取变量

ios - Objective-C 属性和实例变量

java - 如何根据文本断言元素 - Selenium WebDriver with JAVA