Position of rightmost common bit in two numbers | C ++ implementation to find the position of rightmost same bit ; Function to find the position of rightmost set bit in ' n ' ; Function to find the position of rightmost same bit in the binary representations of ' m ' and ' n ' ; position of rightmost same bit ; Driver program to test above
#include <bits/stdc++.h> NEW_LINE using namespace std ; int getRightMostSetBit ( unsigned int n ) { return log2 ( n & - n ) + 1 ; } int posOfRightMostSameBit ( unsigned int m , unsigned int n ) { return getRightMostSetBit ( ~ ( m ^ n ) ) ; } int main ( ) { int m = 16 , n = 7 ; cout << " Position ▁ = ▁ " << posOfRightMostSameBit ( m , n ) ; return 0 ; }