Possible Duplicate:
How do I convert between big-endian and little-endian values in C++?
I was wondering how you would byte swap a 32-bit word
I have a huge buffer of these words and each of them need to be byte swapping due to endianness.
Possible Duplicate:
How do I convert between big-endian and little-endian values in C++?
I was wondering how you would byte swap a 32-bit word
I have a huge buffer of these words and each of them need to be byte swapping due to endianness.
Either use the functions provided by your OS (cf. Martin Beckett's answer), or alternatively, if you are looking for a way to do this out of interest you may be interested in the following code snippet:
x = (x & 0x0000FFFF) << 16 | (x & 0xFFFF0000) >> 16;
x = (x & 0x00FF00FF) << 8 | (x & 0xFF00FF00) >> 8;
Use htonl / ntohl provided by your OS