I need to convert a hex string to binary form in objective-c, Could someone please guide me? For example if i have a hex string 7fefff78, i want to convert it to 1111111111011111111111101111000?
BR, Suppi
See Question&Answers more detail:osI need to convert a hex string to binary form in objective-c, Could someone please guide me? For example if i have a hex string 7fefff78, i want to convert it to 1111111111011111111111101111000?
BR, Suppi
See Question&Answers more detail:osNice recursive solution...
NSString *hex = @"49cf3e";
NSUInteger hexAsInt;
[[NSScanner scannerWithString:hex] scanHexInt:&hexAsInt];
NSString *binary = [NSString stringWithFormat:@"%@", [self toBinary:hexAsInt]];
-(NSString *)toBinary:(NSUInteger)input
{
if (input == 1 || input == 0)
return [NSString stringWithFormat:@"%u", input];
return [NSString stringWithFormat:@"%@%u", [self toBinary:input / 2], input % 2];
}