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;