HebitzLau
HebitzLau

Reputation: 139

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. 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..

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????

Upvotes: 10

Views: 5236

Answers (1)

Manlio
Manlio

Reputation: 10865

You should use

[scanner scanHexInt:&temp];

scanHexInt: expects a pointer, not a value.

Upvotes: 13

Related Questions