Position of rightmost set bit | Javascript implementation of above approach ; Counting the position of first set bit ; Driver code
let INT_SIZE = 32 ; function Right_most_setbit ( num ) { let pos = 1 ; for ( let i = 0 ; i < INT_SIZE ; i ++ ) { if ( ( num & ( 1 << i ) ) == 0 ) pos ++ ; else break ; } return pos ; } let num = 18 ; let pos = Right_most_setbit ( num ) ; document . write ( pos ) ;