To swap endianness, you need to "mirror" the bytes in the value. For instance, to swap the endianness of a 32-bit integer, you'd do something like this:

Code:
int32_t swap(int32_t in)
{
    return ((in & 0x0000FF00) << 8) | ((in & 0x00FF0000) >> 8) |
    			((in & 0x000000FF) << 24) | ((in & 0xFF000000) >> 24);
}
If you can read and understand this piece of code, you should be able to implement functions for swapping endianness of other sized integers (16 bit, 64 bit, etc) aswell.