Highest power of 2 that divides a number represented in binary | Function to return the highest power of 2 which divides the given binary number ; To store the highest required power of 2 ; Counting number of consecutive zeros from the end in the given binary string ; Driver code
function highestPower ( str , len ) { let ans = 0 ; for ( let i = len - 1 ; i >= 0 ; i -- ) { if ( str [ i ] == ' ' ) ans ++ ; else break ; } return ans ; } let str = " " ; let len = str . length ; document . write ( highestPower ( str , len ) ) ;