开发者

How to convert decimal into octal in objective c

just like my question, How c开发者_如何学运维an i convert decimal into octal in objective c? can somebody help me? it's make me dizy


You have to initialize a new NSString object using the right format specifier.

Like :

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

This will create an autoreleased NSString object containing octal string representation of i. In case you start from a NSString containing a decimal number representation, you should first retrieve the number using :

int i = [myDecimalNumberAsAString intValue];

Here is a link to the format specifiers reference.

Hope this helps.


Since Objective C is a superset of C you can just use C functions such as sprintf, e.g.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜