I have a large array of bytes called memory and I'm trying to convert 8 of those bytes to a uint64_t. I'm trying to print the number in big-endian.
I have this so far:
uint64_t value = (uint64_t)(memory[256]) | //location contains byte 88
(uint64_t)(memory[257]) << 8 | //77
(uint64_t)(memory[258]) << 16 | //66
(uint64_t)(memory[259]) << 24 | //55
(uint64_t)(memory[260]) << 32 | //44
(uint64_t)(memory[261]) << 40 | //33
(uint64_t)(memory[262]) << 48 | //22
(uint64_t)(memory[263]) << 56; //11
I print like so:
printf("0x%x", value);
The output is 0x55667788
, but I want the output to be 0x1122334455667788
.
Any suggestions of how I can fix the above code to print 0x1122334455667788
?
Solution: The print statement needed to be:
printf("0x%lx", value);