views:

90

answers:

1

NSLog function accepts printf format specifiers. My question is about %x specifier. Does this print hex codes as sequence on memory? Or does it have it's own printing sequence style?

unsigned int a = 0x000000FF;
NSLog(@"%x", a);

Results of above code on little or big endian processors are equal or different? And how about NSString's -initWithFormat method? Does it follows this rule equally?

+3  A: 

%x always prints the most significant digits first. Doesn't matter what kind of processor it is running on.

progrmr
+1, `NSLog` and the `int` are both in the same endianness.
Carl Norum
@Carl can you tell me more specifically? Did you mean byte order can be different by machine?
Eonil
@Eonil, yeah for sure. For example, PowerPC macs are big-endian, and Intel macs are little-endian.
Carl Norum