Find the maximum between N and the number formed by reversing 32 | Function that obtains the number using said operations from N ; Stores the binary representation of the number N ; Find the binary representation of the number N ; Check for the set bits ; Reverse the string S ; Stores the obtained number ; Calculating the decimal value ; Check for set bits ; Function to find the maximum value between N and the obtained number ; Driver Code
function reverseBin ( N ) { let S = " " ; let i ; for ( i = 0 ; i < 32 ; i ++ ) { if ( N & ( 1 << i ) ) S += ' ' ; else S += ' ' ; } S = S . split ( " " ) . reverse ( ) . join ( " " ) ; let M = 0 ; for ( i = 0 ; i < 32 ; i ++ ) { if ( S [ i ] == ' ' ) M += ( 1 << i ) ; } return M ; } function maximumOfTwo ( N ) { let M = reverseBin ( N ) ; return Math . max ( N , M ) ; } let N = 6 ; document . write ( maximumOfTwo ( N ) ) ;