How to convert decimal to octal in c lens

as my question is, How can I convert decimal to octal in objective c? can someone help me? it makes me dizy

-2
source share
2 answers

You must initialize a new NSString object using the correct format specifier.

Like:

 int i = 9; NSString *octalString = [NSString stringWithFormat:@"%o", i]; // %O works too. 

This will create an autotleased NSString object containing the octal string representation of i . If you start with an NSString containing a decimal representation, you must first get the number using:

 int i = [myDecimalNumberAsAString intValue]; 

Here is the link to the link of the format specifiers.

Hope this helps.

0
source

Since Objective-C is a superset of C, you can simply use C functions like sprintf , for example

 char s[32]; int n = 42; sprintf(s, "%o", n); 
0
source

Source: https://habr.com/ru/post/927346/


All Articles