Conversion from hex value to acsii character

Posted on 2011-10-21
Medium Priority
Last Modified: 2012-05-12

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

Question by:pizdzielec
LVL 33

Accepted Solution

pgnatyuk earned 2000 total points
ID: 37010362
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


Author Closing Comment

ID: 37010874
Thx mate, the NSScaner do the job.


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

     Intro      In this article, I will show you how to parse a JSON in Swift using an open source library called SwiftyJSON (https://github.com/SwiftyJSON/SwiftyJSON). If you haven't heard of a JSON before, it stands for JavaScript Object Notation…
How to take pictures with depth using iOS 10
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question