- (NSData *)hexToBytes:(NSString *)str { NSMutableData* data = [NSMutableData data]; int idx; for (idx = 0; idx+2 <= str.length; idx+=2) { NSRange range = NSMakeRange(idx, 2); NSString* hexStr = [str substringWithRange:range]; NSScanner* scanner = [NSScanner scannerWithString:hexStr]; unsigned int intValue; [scanner scanHexInt:&intValue]; [data appendBytes:&intValue length:1]; } return data; } 可以把@"3C2B89"转成<3c2b89>