// foo vector of unsigned chars
// contains 0x00, 0x00, 0xb8, 0x01, 0x00, 0x00, 0x00, 0x1F, 0xEC 0x82
std::vector< unsigned char > foo;
long some_long = (long)&foo[6];
// i want the unsigned chars 0x00, 0x1F, 0xEC 0x82 to
// make up the long decimal value of 2092162
Now the above would work if my system was big-endian however how do i get this to work for little-endian?
Also is the above way preferred? or should I be using something like below:
std::copy(&foo[6], &foo[6] + sizeof(long), reinterpret_cast<unsigned char*>(&some_long));