Working with hex in objective-c

I can not get simple thing to work in objective-c - just lack of experience. Maybe someone could point me in the right direction.

I have two NSStrings, in this format the information passes from other object. So in case of working with other formats (eg. NSData) I need to convert them. Yet, even converting to NSData I have no idea how to make it done.

NSString *year = @"FC"; ( 1111 1100 )
NSString minutes* = @"0"; ( 0000 0000 )

I need to cut first bits from year and add them to minutes. The result should be like this:

year = 3C ( 0011 1100 )
minutes = 30 ( 0011 0000 )

How should i do this ?


In order to convert the strings to integers, use C standard library functions:

NSString *year = @"FC";
NSString *minutes = @"0";
int yearInt = strtol([year UTF8String], NULL, 16);
int minInt = strtol([minutes UTF8String], NULL, 16);

minInt += (year >> 6) & 0x03;


Need Your Help

How to convert between Key and String in Swift?

ios swift dictionary

I'm making an extension on Dictionary, just a convenience method to traverse a deep json structure to find a given dictionary that might be present. In the general extension of a Dictionary, i'm no...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.