Highest power of 2 that divides a number represented in binary | Java implementation of the approach ; Function to return the highest power of 2 which divides the given binary number ; To store the highest required power of 2 ; Counting number of consecutive zeros from the end in the given binary string ; Driver code
class GFG { static int highestPower ( String str , int len ) { int ans = 0 ; for ( int i = len - 1 ; i >= 0 ; i -- ) { if ( str . charAt ( i ) == '0' ) ans ++ ; else break ; } return ans ; } public static void main ( String [ ] args ) { String str = "100100" ; int len = str . length ( ) ; System . out . println ( highestPower ( str , len ) ) ; } }