Position of rightmost common bit in two numbers | Function to find the position of rightmost same bit in the binary representations of ' m ' and ' n ' ; Initialize loop counter ; Check whether the value ' m ' is odd ; Check whether the value ' n ' is odd ; Below ' if ' checks for both values to be odd or even ; Right shift value of m ; Right shift value of n ; When no common set is found ; Driver code
function posOfRightMostSameBit ( m , n ) { let loopCounter = 1 ; while ( m > 0 n > 0 ) { let a = m % 2 == 1 ; let b = n % 2 == 1 ; if ( ! ( a ^ b ) ) { return loopCounter ; } m = m >> 1 ; n = n >> 1 ; loopCounter ++ ; } return - 1 ; } let m = 16 , n = 7 ; document . write ( " " + posOfRightMostSameBit ( m , n ) ) ;