Program to check if a number can be expressed as an even power of 2 or not | Function to check if N can be expressed as an even power of 2 or not ; Iterate until low > high ; Calculate mid ; If 2 ^ mid is equal to n ; If mid is odd ; Update the value of low ; Update the value of high ; Otherwise ; Driver code
function checkEvenPower ( n ) { var low = 0 , high = n ; while ( low <= high ) { var mid = low + ( high - low ) / 2 ; var value = parseInt ( Math . pow ( 2 , mid ) ) ; if ( value == n ) { if ( mid % 2 == 1 ) return " " ; else return " " ; } else if ( value < n ) low = mid + 1 ; else high = mid - 1 ; } return " " ; } var N = 4 ; document . write ( checkEvenPower ( N ) ) ;