OC Swift Hex字符串转为uint8数组
swift
let data = NSString(string : "ca 20 fe c1 04 03 03 07 01 ac")
let dataArr = data.componentsSeparatedByString(" ")
var bytes : [UInt8] = []
for item in dataArr {
let byte = UInt8(item, radix: 16)
bytes.append(byte!);
let hexData = NSData(bytes: bytes, length: 10)
NSString *strData = @"ca 20 fe c1 04 03 03 07 00 ac";
NSArray<NSString *> *dataArr = [strData componentsSeparatedByString:@" "];
UInt8 bytes[dataArr.count];
for (NSInteger i = 0; i< dataArr.count; i++) {
NSString *obj = dataArr[i];
UInt8 byte = (UInt8)strtoul([obj UTF8String],0,16);
bytes[i] = byte;
// NSData *data = [NSData dataWithBytes:bytes length:dataArr.count];