【问题标题】:How to get an int in decimal from a Hex NSString如何从 Hex NSString 中获取十进制整数
【发布时间】:2012-02-17 01:39:23
【问题描述】:

我想从一个十六进制编码的字符串中获取一个 dec 值, 例如:A->10、B->11 等。 我编码如下

NSString *tempNumber;
tempNumber=number.text; 
NSScanner *scanner=[NSScanner scannerWithString:tempNumber];
unsigned int temp;
[scanner scanHexInt:temp];
NSLog(@"%@:%d",tempNumber,temp);

但是 NSLog 输出不是我喜欢的..

2012-01-24 01:34:57.703 TestingUnit[34861:f803] 4:-1073750472
2012-01-24 01:35:01.133 TestingUnit[34861:f803] 6:-1073750408
2012-01-24 01:35:01.983 TestingUnit[34861:f803] 2:-1073750408
2012-01-24 01:35:02.414 TestingUnit[34861:f803] 1:-1073750408

谁能告诉我怎么解决这个问题???

【问题讨论】:

标签: iphone objective-c ios


【解决方案1】:

你应该使用

[scanner scanHexInt:&temp];

scanHexInt: 需要一个指针,而不是一个值。

【讨论】:

    猜你喜欢
    • 2011-07-12
    • 2017-12-22
    • 2018-09-03
    • 2021-04-12
    • 2012-05-04
    • 2012-09-04
    • 1970-01-01
    • 2010-09-18
    • 1970-01-01
    相关资源
    最近更新 更多