[英]How to get an int in decimal from a Hex NSString
I would like to get a dec value from a Hex-encoded string, for examples: A->10, B->11,etc. 我想从十六进制编码的字符串中获取十进制值,例如:A-> 10,B-> 11等。 and I coded as the following 我编码如下
NSString *tempNumber;
tempNumber=number.text;
NSScanner *scanner=[NSScanner scannerWithString:tempNumber];
unsigned int temp;
[scanner scanHexInt:temp];
NSLog(@"%@:%d",tempNumber,temp);
but the NSLog output isn't what I perfer.. 但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
could someone tell me how can I solve this???? 谁能告诉我怎么解决这个问题????
You should use 你应该用
[scanner scanHexInt:&temp];
scanHexInt:
expects a pointer, not a value. scanHexInt:
期望一个指针,而不是一个值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.