How to convert unsigned int to NSString?

I have an unsinged int having a value of -10, now I want to convert it to NSString.

We just do, as in objective-c, iphone programming

int x = 10;
NSString *str = [NSString stringWithFormat:@"%d",x];
NSLog(@"My String is %@",str);

I will show console output as 10

but if it's something like

unsigned int x = -10;
NSString *str = [NSString stringWithFormat:@"%d",x];
NSLog(@"My String is %@",str);

Then the output will be the same, not -10,

how can i do the right conversion?

+3
source share
3 answers

Use %uinstead %d. It is similar to C: convert signed unsigned .

+3
source

Have you ever asked yourself what unsigned means ?

This is always> = 0. -10 is not a valid value for an unsigned variable.

+11
source

-10.

+3

All Articles