Are there any Cocoa classes that will help me convert a hex value in a NSString like 0x12FA
to a long
or NSNumber
? It doesn't look like any of the classes like NSNumberFormatter
support hex numbers.
Thanks, Hua-Ying
Are there any Cocoa classes that will help me convert a hex value in a NSString like 0x12FA
to a long
or NSNumber
? It doesn't look like any of the classes like NSNumberFormatter
support hex numbers.
Thanks, Hua-Ying
See NSScanner's scanHex...: methods. That'll get you the primitive that you can wrap in an NSNumber.
Here's a short example of how you would do it using NSScanner:
NSString* pString = @"0xDEADBABE";
NSScanner* pScanner = [NSScanner scannerWithString: pString];
unsigned int iValue;
[pScanner scanHexInt: &iValue];