添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
眼睛小的小蝌蚪  ·  SQL ...·  2 月前    · 
爱笑的木瓜  ·  CentOS7 安装WPS: ...·  1 年前    · 
精彩文章免费看

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];