Position of rightmost different bit | C ++ implementation to find the position of rightmost different bit ; Function to find the position of rightmost set bit in ' n ' returns 0 if there is no set bit . ; to handle edge case when n = 0. ; Function to find the position of rightmost different bit in the binary representations of ' m ' and ' n ' returns 0 if there is no rightmost different bit . ; position of rightmost different bit ; Driver program
#include <bits/stdc++.h> NEW_LINE using namespace std ; int getRightMostSetBit ( int n ) { if ( n == 0 ) return 0 ; return log2 ( n & - n ) + 1 ; } int posOfRightMostDiffBit ( int m , int n ) { return getRightMostSetBit ( m ^ n ) ; } int main ( ) { int m = 52 , n = 24 ; cout << " Position ▁ of ▁ rightmost ▁ different ▁ bit : " << posOfRightMostDiffBit ( m , n ) << endl ; return 0 ; }