Position of rightmost common bit in two numbers | Python3 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 Code
import math NEW_LINE ' NEW_LINE def getRightMostSetBit ( n ) : NEW_LINE INDENT return int ( math . log2 ( n & - n ) ) + 1 NEW_LINE DEDENT ' NEW_LINE def posOfRightMostSameBit ( m , n ) : NEW_LINE INDENT return getRightMostSetBit ( ~ ( m ^ n ) ) NEW_LINE DEDENT m , n = 16 , 7 NEW_LINE print ( " Position ▁ = ▁ " , posOfRightMostSameBit ( m , n ) ) NEW_LINE