Method 1:
extract the high byte hibyte = (x & 0xff00) >> 8;
extract the low byte lobyte = (x & 0xff);
combine them in the reverse order x = lobyte << 8 | hibyte;
Method 2:
typedef union mini
{
unsigned char b[2];
unsigned short s;
} micro;
unsigned short swap_bytes(unsigned short x)
{
micro y;
y.s = b;
unsigned char tmp = y.b[0];
y.b[0] = y.b[1];
y.b[1] = tmp;
return y.s
}