What I want to do should actually be quite simple, but I don't know how to achieve it in a simple way:
I want to copy the value of an unsigned integer (32 Bit) to an array of unsigned chars. The representation inside the array must always be in little endian.
On an little endian architecture I can simple do:
unsigned char array[sizeof(unsigned int)];
unsigned int i = 12345;
memcpy(array, &i, sizeof(unsigned int));
The representation will be in little endian. What is the best way to achieve this on a big endian architecture? And how do I figure out the endianess of my architecture inside my Code?
My project uses the C++11 standard.
Thanks in advance!