I have a hex NSString and I want to be able to pack that to a char array.
For example, I have a NSString:
NSString* hex = "AABBCCDD";
and I want to be able to convert that to a char array for use with CCCrypt:
char bytes[] = { 0xAA, 0xBB, 0xCC, 0xDD };
How could I do this?
You can use a for loop to go through each two byte hexadecimal character. Then, use
NSScannerto read it into a char variable for your character array.Note that this will only work if
hexStringhas an even length (i.e. divisible by two).