Swap every two bits in bytes | C # program to swap every two bits in a byte . ; Extracting the high bit shift it to lowbit Extracting the low bit shift it to highbit ; Driver function to test above function
using System ; public class GFG { static uint swapBitsInPair ( uint x ) { return ( ( x & 010101010 ) >> 1 ) | ( ( x & 001010101 ) << 1 ) ; } static public void Main ( ) { uint x = 4 ; Console . WriteLine ( swapBitsInPair ( x ) ) ; } }