iOS字符串转byte数据类型


NSString *string = @"18";
int intAngle = [string intValue];
NSString *hexString = [NSString stringWithFormat:@"%@",[[NSString alloc]initWithFormat:@"%01x",intAngle]];

NSScanner*scanner = [NSScannerscannerWithString:hexString];

unsigned int intValue;

[scannerscanHexInt:&intValue];

NSData*data = [NSDatadataWithBytes:&intValuelength:sizeof(intValue)];

Byte*byte = (Byte*)[dataStrbytes];

打印结果为'\x12'

你可能感兴趣的:(iOS字符串转byte数据类型)