text: Highest power of 2 less than or equal to given number | Java program to find highest power of 2 smaller than or equal to n . ; If i is a power of 2 ; Driver code
code: class GFG { static int highestPowerof2 ( int n ) { int res = 0 ; for ( int i = n ; i >= 1 ; i -- ) { if ( ( i & ( i - 1 ) ) == 0 ) { res = i ; break ; } } return res ; } public static void main ( String [ ] args ) { int n = 10 ; System . out . print ( highestPowerof2 ( n ) ) ; } }