text: 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
code: < ? php function isDivisible ( $ str , $ k ) { $ n = strlen ( $ str ) ; $ c = 0 ; for ( $ i = 0 ; $ i < $ k ; $ i ++ ) if ( $ str [ $ n - $ i - 1 ] == '0' ) $ c ++ ; return ( $ c == $ k ) ; } $ str1 = "10101100" ; $ k = 2 ; if ( isDivisible ( $ str1 , $ k ) ) echo " Yes " , " STRNEWLINE " ; else echo " No " , " STRNEWLINE " ; $ str2 = "111010100" ; $ k = 2 ; if ( isDivisible ( $ str2 , $ k ) ) echo " Yes " , " STRNEWLINE " ; else echo " No " , " STRNEWLINE " ; ? >