Try this to swap all consecutive bits
For 8 bit integer
u_int8 swap_bits(u_int8 ch) { return ((ch & 0xAA)>>;1 ) | ( (ch & 0x55) << 1); }
For 16 bit integer
u_int16 swap_bits(u_int16 ch) { return ((ch & 0xAAAA)>>;1 ) | ( (ch & 0x5555) << 1); }
Write a program to reverse the bits of an unsigned integer ??
How to swap ith and jth Bits for a 32-Bit Integer?
What is the simples way to check if the sum of two unsigned integers has resulted in an overflow.