Position of rightmost set bit | PHP implementation of above approach ; counting the position of first set bit ; Driver code
< ? php function Right_most_setbit ( $ num ) { $ pos = 1 ; $ INT_SIZE = 32 ; for ( $ i = 0 ; $ i < $ INT_SIZE ; $ i ++ ) { if ( ! ( $ num & ( 1 << $ i ) ) ) $ pos ++ ; else break ; } return $ pos ; } $ num = 18 ; $ pos = Right_most_setbit ( $ num ) ; echo $ pos ; echo ( " STRNEWLINE " ) ? >