typedef unsigned char Byte;
...
void ReverseBytes( void *start, int size )
{
Byte *buffer = (Byte *)(start);
for( int i = 0; i < size / 2; i++ ) {
A performant solution without using the STL:
void reverseBytes(void *start, int size) {
unsigned char *lo = start;
unsigned char *hi = start + size - 1;
unsigned char swap;
while (lo < hi) {
swap = *lo;
*lo++ = *hi;
*hi-- = swap;
}
}
Though the question is 3 ½ years old, chances are that someone else will be searching for the same thing. That's why I still post this.