text: Check divisibility of binary string by 2 ^ k | C # implementation to check whether given binary number is evenly divisible by 2 ^ k or not ; 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 ; Driver program to test above ; first example ; Second example
code: using System ; class GFG { static bool isDivisible ( String str , int k ) { int n = str . Length ; int c = 0 ; for ( int i = 0 ; i < k ; i ++ ) if ( str [ n - i - 1 ] == '0' ) c ++ ; return ( c == k ) ; } public static void Main ( ) { String str1 = "10101100" ; int k = 2 ; if ( isDivisible ( str1 , k ) == true ) Console . Write ( " Yes STRNEWLINE " ) ; else Console . Write ( " No " ) ; String str2 = "111010100" ; k = 2 ; if ( isDivisible ( str2 , k ) == true ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }