Check whether the binary equivalent of a number ends with "001" or not | Java 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 "001" or not ; To store the binary number ; Count used to store exponent value ; Driver code
class GFG { static boolean isSuffix ( String s1 , String s2 ) { int n1 = s1 . length ( ) ; int n2 = s2 . length ( ) ; if ( n1 > n2 ) return false ; for ( int i = 0 ; i < n1 ; i ++ ) if ( s1 . charAt ( n1 - i - 1 ) != s2 . charAt ( n2 - i - 1 ) ) return false ; return true ; } static boolean CheckBinaryEquivalent ( int N ) { 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 = Integer . toString ( B_Number ) ; return isSuffix ( "001" , bin ) ; } public static void main ( String [ ] args ) { int N = 9 ; if ( CheckBinaryEquivalent ( N ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }