Conversion from hex value to acsii character

Hi,

I'm looking way to convert hex string to ascii letters. As you can see, after some calculation at Licence_crc(customerNumberTmp_2, CRC); I will get some integer value, like 5144414C.
Next, I tried to convert this value to corresponding ascii letters but all I got is rubbish. I know why but I don't know how to make it working.
 
NSInteger CRC = 0;
Licence_crc(customerNumberTmp_2, CRC);

NSString *CRC_2 = [NSString stringWithFormat:@"%X", CRC];

int CRC_2_length = [CRC_2 length];        
        
NSMutableString *characters = [NSMutableString stringWithCapacity:CRC_2_length];

for (int i=0; i < 8; i=i+2) {
	NSString *ichar  = [NSString stringWithFormat:@"%c", [CRC_2 substringWithRange:NSMakeRange(i,2)]];
	[characters appendString:ichar];
}

Open in new window

pizdzielecAsked:
Who is Participating?
 
pgnatyukCommented:
I attached a code that converts a hex number to unsigned int. [NSString stringWithFormat:@"%d", value] will make a string from the value variable.
Take a look, if that's what you need.

unsigned int value = 0;
NSString* hexString = @"ff";
NSScanner* scan = [NSScanner scannerWithString:hexString];
[scan scanHexInt:&value];
NSLog(@"value %d", value);

Open in new window

0
 
pizdzielecAuthor Commented:
Thx mate, the NSScaner do the job.

Cheers,
P.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.