Swap every two bits in bytes | Java 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
import java . util . * ; class GFG { static int swapBitsInPair ( int x ) { return ( ( x & 0b10101010 ) >> 1 ) | ( ( x & 0b01010101 ) << 1 ) ; } public static void main ( String [ ] args ) { int x = 4 ; System . out . print ( swapBitsInPair ( x ) ) ; } }