Count trailing zeroes present in binary representation of a given number using XOR | Java implementation of the above approach ; Function to print count of trailing zeroes present in binary representation of N ; Stores XOR of N and ( N - 1 ) ; Return count of set bits in res ; Driver Code ; Function call to print the count of trailing zeroes in the binary representation of N
import java . io . * ; class GFG { public static int countTrailingZeroes ( int N ) { int res = N ^ ( N - 1 ) ; return ( int ) ( Math . log ( temp ) / Math . log ( 2 ) ) ; } public static void main ( String [ ] args ) { int N = 12 ; System . out . println ( countTrailingZeroes ( N ) ) ; } }