First number to leave an odd remainder after repetitive division by 2 | Function to return the position least significant set bit ; Function return the first number to be converted to an odd integer ; Stores the positions of the first set bit ; If both are same ; If A has the least significant set bit ; Otherwise ; Driver Code
function getFirstSetBitPos ( n ) { return ( Math . log ( n & - n ) / Math . log ( 2 ) ) ; } function oddFirst ( a , b ) { let steps_a = getFirstSetBitPos ( a ) ; let steps_b = getFirstSetBitPos ( b ) ; if ( steps_a == steps_b ) { return - 1 ; } else if ( steps_a > steps_b ) { return b ; } else { return a ; } } let a = 10 ; let b = 8 ; document . write ( oddFirst ( a , b ) ) ;