Count trailing zeroes present in binary representation of a given number using XOR | C ++ implementation of the above approach ; Function to print count of trailing zeroes present in binary representation of N ; Count set bits in ( N ^ ( N - 1 ) ) ; If res < 0 , return 0 ; Driver Code ; Function call to print the count of trailing zeroes in the binary representation of N
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countTrailingZeroes ( int N ) { int res = log2 ( N ^ ( N - 1 ) ) ; return res >= 0 ? res : 0 ; } int main ( ) { int N = 12 ; cout << countTrailingZeroes ( N ) ; return 0 ; }