Swap every two bits in bytes | PHP 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 Code
< ? php function swapBitsInPair ( $ x ) { return ( ( $ x & 0b10101010 ) >> 1 ) | ( ( $ x & 0b01010101 ) << 1 ) ; } $ x = 4 ; echo swapBitsInPair ( $ x ) ; ? >