unsigned short reverse(unsigned short x) { x = (x & 0xFF) << 8 | (x & 0xFF00) >> 8; return x; }