unsigned int outVal; NSScanner* scanner = [NSScanner scannerWithString:@"9EF"]; [scanner scanHexInt:&outVal]; NSLog(@"%d", outVal);
上面的代码会输出2543
@"9EF"也可以是@"0x9EF",十六进制数字的大小写都可以。
unsigned int outVal; NSScanner* scanner = [NSScanner scannerWithString:@"9EF"]; [scanner scanHexInt:&outVal]; NSLog(@"%d", outVal);