I am confused as to how, endianness swaps the ordering of elements of a uint32_t
array when converted to a uint64_t
and vice-versa.
If I'm dealing with bytes stored in a uint8_t array of 8 elements, if I directly convert it to a uint64_t
using pointer casting and dereference like this:
uint8_t array[8] = {0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0xb0, 0xa0};
uint64_t u = *(uint64_t *)array;
On a little endian system, u
would be equal to 0xa0b0ffeeddccbbaa
But, if I have a uint32_t
array like this:
uint32_t arr[2] = {0xaabbccdd, 0xeeffb0a0} ;
uint64_t U = *(uint64_t *)arr;
On a little endian system, U
becomes 0xeeffb0a0aabbccdd
I intuitively understand the former case, but the latter, with the uint32_t
is confusing!
I have trouble visualizing the memory layout, during conversion, in the latter case...
Every help, will be greatly appreciated!