Check whether the number has only first and last bits set | Set 2 | function to check whether the number has only first and last bits set ; Driver Code
< ? php function onlyFirstAndLastAreSet ( $ n ) { if ( $ n == 1 ) return true ; if ( $ n == 2 ) return false ; return ( ( ( $ n - 1 ) & ( $ n - 2 ) ) == 0 ) ; } $ n = 9 ; if ( onlyFirstAndLastAreSet ( $ n ) ) echo " Yes " ; else echo " No " ; ? >