给定这样一个数组的例子:
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 中实现这一目标?
最佳答案
要获得十进制和十六进制等价物,您可以:
int number = 0xe; // or 0x3, 0x6, 0x8, 0x2
NSString * decimalString = [NSString stringWithFormat:@"%d", number];
NSString * hexString = [NSString stringWithFormat:@"%x", number];
关于objective-c - 如何在 Objective C 中将十六进制数转换为整数和字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/934790/