The IMO simplest way is using a union:
Code:
union
{
unsigned char a[4];
unsigned long l;
} conv;
Just assign to one, read the other.
The other way is casting pointers:
Code:
unsigned long l = *reinterpret_cast<unsigned long *>(a);
The third way uses shifts (this is the one where you can control endianness):
Code:
unsigned long l = a[0] | a[1] << 8 | a[2] << 16 | a[3] << 24;
In all cases, remember that on my Athlon64, gcc will have 8-byte longs, so the result might not be what you expect. If your compiler has it, include <stdint.h> and use uint32_t instead. This header is part of the C99 standard. If it doesn't have it, or you just want to be portable, include <boost/cstdint.hpp> from the Boost libraries. It defines the same types, but in the boost namespace.