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