Convert int64 to NSData

I need to convert a long value from int64 to NSData, so I can run the hash algorithm on it later. I am doing:

int64_t longNumber = 9000000000000000000L;
NSMutableData *buffer = [NSMutableData dataWithBytes:&longNumber length:sizeof(longNumber)];

NSLog(@"%lld", [buffer bytes]);
NSLog(@"%lld", longNumber);

The resulting console output is as follows:

6201314301187184 9000000000000000000

Why is NSData incorrectly storing a long number value? If I run this in a loop, the byte drift is NSData, starting at 620, then 621 onwards. Am I outputting the longNumber address via [buffer bytes], and not its value?

+3
source share
1 answer

: -, , . 9000000000000000000L 9000000000000000000LL, .

-, , . NSLog :

NSLog(@"%lld", *((int64_t*)[buffer bytes]));

.

+7

Source: https://habr.com/ru/post/1708043/


All Articles