Maximize the number by rearranging bits | An efficient Java program to find minimum number formed by bits of a given number . ; Returns maximum number formed by bits of a given number . ; _popcnt32 ( a ) gives number of 1 's present in binary  representation of a. ; If a$32 bits are set . ; find a number witn n least significant set bits . ; Now shift result by 32 - n ; Driver Code
< ? php function _popcnt32 ( $ n ) { $ count = 0 ; while ( $ n != 0 ) { $ n = $ n & ( $ n - 1 ) ; $ count ++ ; } return $ count ; } function maximize ( $ a ) { $ n = _popcnt32 ( $ a ) ; if ( $ n == 32 ) return $ a ; $ res = ( 1 << $ n ) - 1 ; return ( $ res << ( 32 - $ n ) ) ; } $ a = 3 ; echo ( maximize ( $ a ) ) ; ? >