TITLE: another way to swap bytes RESPONSE: neil@ninthwv.demon.co.uk (Neil Topham) For a 16-bit types use; newvalue = ((oldvalue & 0xff) << 8) | ((oldvalue & 0xff00) >> 8); RESPONSE: Peter Gustav Lindstrom , 20 Jul 95 This is only guaranteed to work if oldvalue is unsigned, otherwise it is implementation dependent (i.e. either 0's or 1's will be shifted in from the left). A better way of doing it would be to do the AND after the shift: newvalue = ((oldvalue << 8) & 0xff00) | ((oldvalue >> 8) & 0xff); Another alternative is to use unions (this is assuming 16 bit shorts): unsigned short swapShort(unsigned short x) { union { unsigned short s; unsigned char c[2]; } u; u.s = x; u.c[0] ^= u.c[1]; u.c[1] ^= u.c[0]; u.c[0] ^= u.c[1]; return u.s; }