Advertisements
Octal to Decimal Converter
Example Code
NSString *octalString = @"17"; /* Octal to Dec*/ NSLog(@"Decimal Value for Octal String is %ld", strtol(octalString.UTF8String, NULL, 8)); /* Octal to Hex*/ NSLog(@"Hex Value for Octal String is %@",[NSString stringWithFormat:@"%2lX", strtol(octalString.UTF8String, NULL, 8)]); /* Octal to Binary*/ NSUInteger decimalNumber = [decimalString integerValue]; int index = 0; NSString *binary = @""; while (decimalNumber > 0) { binary = [[NSString stringWithFormat:@"%lu", decimalNumber&1] stringByAppendingString:binary]; decimalNumber = decimalNumber>> 1; ++index; } NSLog(@"Binary Value for Octal String is %@", binary);
Result
Decimal Value for Octal String is 15 Hex Value for Octal String is F Binary Value for Octal String is 1111
Advertisements