Results for tag: hexstring
Convert a NSString hexstring to a NSData [objectivec]
![](images/comment.png)
NSString *hexStr = YOUR_NSSTRING_HEXSTRING;
// remove whitespace from the hexstring
hexStr = [hexStr stringByReplacingOccurrencesOfString:@" " withString:@""];
// instantiate an empty NSMutableData (it will represent the final NSData)
NSMutableData *hexData= [[NSMutableData alloc] init];
unsigned char whole_byte;
char byte_chars[3] = {'\0','\0','\0'};
// converting hex to bytes
for (int i=0; i < [hexStr length]/2; i++) {
byte_chars[0] = [hexStr characterAtIndex:i*2];
byte_chars[1] = [hexStr characterAtIndex:i*2+1];
whole_byte = strtol(byte_chars, NULL, 16);
[hexData appendBytes:&whole_byte length:1];
}
0/5 - [0 rating]