Search code examples
objective-cnsdata

NSData object from created from unsigned 64-bit integer is reversed


In Xcode 5.0.2 on OS X 10.9.1:

uint64_t data = 0x6ffa9e58938d7f5d;
NSData *nsdataObj = [NSData dataWithBytes:&data length:8];
NSLog(@"%@", nsdataObj);

Output:

<5d7f8d93 589efa6f>

How/why is the data getting reversed?


Solution

  • Because Endianness apparently. (Thanks @Hot Licks and @Josh Caswell!) Solved the issue by using the Core Foundation byte order function CFSwapInt64.