text: Highest power of 2 less than or equal to given number | PHP program to find highest power of 2 smaller than or equal to n . ; If i is a power of 2 ; Driver code
code: < ? php function highestPowerof2 ( $ n ) { $ res = 0 ; for ( $ i = $ n ; $ i >= 1 ; $ i -- ) { if ( ( $ i & ( $ i - 1 ) ) == 0 ) { $ res = $ i ; break ; } } return $ res ; } $ n = 10 ; echo highestPowerof2 ( $ n ) ; ? >