text: Highest power of 2 less than or equal to given number | C # code to find highest power of 2 smaller than or equal to n . ; If i is a power of 2 ; Driver Code
code: using System ; class GFG { public 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 ; } static public void Main ( ) { int n = 10 ; Console . WriteLine ( highestPowerof2 ( n ) ) ; } }