Skip to content

Instantly share code, notes, and snippets.

@wess
Created June 17, 2016 16:16
Show Gist options
  • Select an option

  • Save wess/ad6da41fb52c731f0c47781c7ffcb497 to your computer and use it in GitHub Desktop.

Select an option

Save wess/ad6da41fb52c731f0c47781c7ffcb497 to your computer and use it in GitHub Desktop.
- (NSString *)stringFromHexString:(NSString *)hexString {
if (([hexString length] % 2) != 0)
return nil;
NSMutableString *string = [NSMutableString string];
for (NSInteger i = 0; i < [hexString length]; i += 2) {
NSString *hex = [hexString substringWithRange:NSMakeRange(i, 2)];
unsigned int decimalValue = 0;
sscanf([hex UTF8String], "%x", &decimalValue);
[string appendFormat:@"%c", decimalValue];
}
return string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment