5

给定这样的数组示例:

idx = [ 0xe, 0x3,  0x6, 0x8, 0x2 ]

我想获得Objective C中每个指定项目的整数和字符串表示形式。我模拟了一个完美运行的ruby示例:

0xe gives 14 when i run 0xe.to_i and "e" when i run to_i(base=16)
0x3 gives 3 when i run 0x3.to_i and gives 3 when i run to_i(base=16) 

如何在 Objective C 中实现这一点?

4

2 回答 2

10

To get the decimal and hexadecimal equivalents, you would do:

int number = 0xe; // or 0x3, 0x6, 0x8, 0x2

NSString * decimalString = [NSString stringWithFormat:@"%d", number];
NSString * hexString = [NSString stringWithFormat:@"%x", number];
于 2009-06-01T13:49:07.213 回答
0

有了 NSString 后,您就可以使用该类中的方法,例如 intValue 或 longValue 或 floatValue

于 2009-07-10T19:31:36.533 回答