下面这个是将16进制转换成2进制数据
+ (NSData *)hex2data:(NSString *)hex {
NSMutableData *data = [NSMutableData dataWithCapacity:hex.length / 2];
unsigned char whole_byte;
char byte_chars[3] = {'\0','\0','\0'};
int i;
for (i=0; i < hex.length / 2; i++) {
byte_chars[0] = [hex characterAtIndex:i*2];
byte_chars[1] = [hex characterAtIndex:i*2+1];
whole_byte = strtol(byte_chars, NULL, 16);
[data appendBytes:&whole_byte length:1];
}
return data;
}