Position of rightmost different bit | Python implementation to find the position of rightmost different bit ; Function to find the position of rightmost set bit in 'n ; to handle edge case when n = 0. ; Function to find the position of rightmost different bit in the binary representations of ' m ' and 'n ; position of rightmost different bit ; Driver code
import math NEW_LINE ' NEW_LINE def getRightMostSetBit ( n ) : NEW_LINE INDENT if ( n == 0 ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT return math . log2 ( n & - n ) + 1 NEW_LINE DEDENT ' NEW_LINE def posOfRightMostDiffBit ( m , n ) : NEW_LINE INDENT return getRightMostSetBit ( m ^ n ) NEW_LINE DEDENT m = 52 NEW_LINE n = 4 NEW_LINE print ( " position ▁ = ▁ " , int ( posOfRightMostDiffBit ( m , n ) ) ) NEW_LINE