Conversion from hex value to acsii character

Posted on 2011-10-21
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

    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

    Thx mate, the NSScaner do the job.


    Featured Post

    Course: HTML5 Mobile App Development with PhoneGap

    PhoneGap can help you leverage your already existing HTML5, JavaScript, and CSS skills in order to create and deploy cross-platform mobile apps.This program comprehensively covers HTML5 mobile app development from top to bottom.

    Join & Write a Comment

         Intro      In this article, I will show you how to parse a JSON in Swift using an open source library called SwiftyJSON ( If you haven't heard of a JSON before, it stands for JavaScript Object Notation…
    There is a security feature on iOS devices that is nearly impenetrable when it has been activated.  This article will provide some possible solutions as well as necessary steps to take to ensure you do not end up with a locked device.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now