Rob Lourens
Rob Lourens

Reputation: 16119

NSString integerValue returns a number in hex

NSString *x = @"12345";
NSInteger nsint = [x integerValue];  
NSLog(@"%x", nsint);

Prints 3039. intValue has the same result. Any idea how I can get the actual decimal value out of that?

Upvotes: 1

Views: 1602

Answers (2)

kennytm
kennytm

Reputation: 523724

  NSLog(@"%d", nsint);

%x means hex format. (See http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html#//apple_ref/doc/uid/TP40004265 for all format specifiers.)

Upvotes: 7

WhirlWind
WhirlWind

Reputation: 14110

NSLog(@"%d", nsint);

%x prints hex; %d prints decimal.

Upvotes: 4

Related Questions