IOS十六进制转十进制
注意:转换前,如果字符串中含有"<" ">" 或空格等非字符串类型,要先将这些字符串去掉。去掉方法参照:
http://www.cnblogs.com/yuanjunliang/articles/4690148.html
去掉后的转换方法为:
NSString *str = @"0000009b 080d31";
str = [str stringByReplacingOccurrencesOfString:@" " withString:@""];
NSMutableArray *arr = [NSMutableArray array];
for (int i = 0; i<str.length; i+=2) {
NSString *subStr = [str substringWithRange:NSMakeRange(i, 2)];
int number = (int)strtoul([subStr UTF8String], 0, 16);
[arr addObject:[NSNumber numberWithInt:number]];
}
str = [str stringByReplacingOccurrencesOfString:@" " withString:@""];
NSMutableArray *arr = [NSMutableArray array];
for (int i = 0; i<str.length; i+=2) {
NSString *subStr = [str substringWithRange:NSMakeRange(i, 2)];
int number = (int)strtoul([subStr UTF8String], 0, 16);
[arr addObject:[NSNumber numberWithInt:number]];
}
NSLog(@"%@",arr);