Check whether the binary equivalent of a number ends with given string or not | C # implementation of the above approach ; Function returns true if s1 is suffix of s2 ; Function to check if binary equivalent of a number ends in "111" or not ; To store the binary number ; Count used to store exponent value ; Driver Code
using System ; using System . Collections ; class GFG { static bool isSuffix ( String s1 , String s2 ) { int n1 = s1 . Length , n2 = s2 . Length ; if ( n1 > n2 ) return false ; for ( int i = 0 ; i < n1 ; i ++ ) if ( s1 [ n1 - i - 1 ] != s2 [ n2 - i - 1 ] ) return false ; return true ; } static bool CheckBinaryEquivalent ( int N , String str ) { int B_Number = 0 ; int cnt = 0 ; while ( N != 0 ) { int rem = N % 2 ; int c = ( int ) Math . Pow ( 10 , cnt ) ; B_Number += rem * c ; N /= 2 ; cnt ++ ; } String bin = B_Number . ToString ( ) ; return isSuffix ( str , bin ) ; } public static void Main ( String [ ] args ) { int N = 23 ; String str = "111" ; if ( CheckBinaryEquivalent ( N , str ) ) Console . WriteLine ( " Yes STRNEWLINE " ) ; else Console . WriteLine ( " No STRNEWLINE " ) ; } }