union Char2Int
{
char c[8];
unsignedint i[2];
} converter;
char start_arry[]={
0x64, 0x61, 0x74, 0x61, 0x2E, 0x74, 0x78, 0x74,
};
for (int i = 0; i < 8; ++i)
converter.c[i] = start_array[i];
int x = converter.i[0];
int y = converter.i[1];
If you are certain your program will only be compiled on little-endian architectures and you aren't bothered by aliasing violations, you can make it even simpler:
1 2 3
int32_t* p = reinterpret_cast<int32_t*>(start_arry);
int32_t x = p[0];
int32_t y = p[1];
int32_t* p = reinterpret_cast<int32_t*>(start_arry);
int32_t x = p[0];
int32_t y = p[1];
to be the most helping solution which works very well for my purposes.
however, i did not mention that i have a much bigger array, and that sometimes the 4 bytes that i want from the array are not always multiple of 4