将正常的字符串转成16进制NSString字符串在转成Byte字节

//将32转成16进制
NSString *sum = @"32"
//strByte的值为20(32的16进制为20)
NSString *strByte = [NSString stringWithFormat:@"%02x",sum];
        unsigned red = strtoul([strByte UTF8String],0,16);
        Byte by =  (Byte) ((0xff & red) );
//by就是想要得到的字节0x20

你可能感兴趣的:(将正常的字符串转成16进制NSString字符串在转成Byte字节)