Check divisibility of binary string by 2 ^ k | Function to check whether given binary number is evenly divisible by 2 ^ k or not ; Count of number of 0 from last ; If count = k , number is evenly divisible , so returns true else false ; First example ; Second example
function isDivisible ( str , k ) { let n = str . length ; let c = 0 ; for ( let i = 0 ; i < k ; i ++ ) if ( str [ n - i - 1 ] == ' ' ) c ++ ; return ( c == k ) ; } let str1 = " " ; let k = 2 ; if ( isDivisible ( str1 , k ) == true ) document . write ( " " + " " ) ; else document . write ( " " ) ; let str2 = " " ; k = 2 ; if ( isDivisible ( str2 , k ) == true ) document . write ( " " ) ; else document . write ( " " ) ;