如何在目标C中将十六进制数转换为整数和字符串?

Grz*_*lak 5 cocoa hex objective-c

给出这样一个数组的例子:

idx = [ 0xe, 0x3,  0x6, 0x8, 0x2 ]
Run Code Online (Sandbox Code Playgroud)

我想获得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) 
Run Code Online (Sandbox Code Playgroud)

如何在Objective C中实现这一目标?

e.J*_*mes 10

要获得十进制和十六进制等效项,您可以:

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

NSString * decimalString = [NSString stringWithFormat:@"%d", number];
NSString * hexString = [NSString stringWithFormat:@"%x", number];
Run Code Online (Sandbox Code Playgroud)