I have some C/C++ code where I have a 16-bit number (uint16_t
), and I need to swap the first 5 bits with the last 5 bits, keeping their left-to-right order within each block of 5 bits. The middle 6 bits need to remain intact. I am not great at bitwise maths/operations so help would be appreciated!
Conceptually speaking, the switching of positions would look like:
ABCDEFGHIJKLMNOP
becomes LMNOPFGHIJKABCDE
or more literally...
10101000000001010
becomes 0101000000010101
.
Any help would be much appreciated!