text: Program to find whether a no is power of two | C # program for above approach ; Function which checks whether a number is a power of 2 ; Base cases '1' is the only odd number which is a power of 2 ( 2 ^ 0 ) ; All other odd numbers are not powers of 2 ; Recursive function call ; Driver code ; True ; False
code: using System ; class GFG { static bool powerOf2 ( int n ) { if ( n == 1 ) return true ; else if ( n % 2 != 0 n == 0 ) return false ; return powerOf2 ( n / 2 ) ; } static void Main ( ) { int n = 64 ; int m = 12 ; if ( powerOf2 ( n ) ) { Console . Write ( " True " + " STRNEWLINE " ) ; } else { Console . Write ( " False " + " STRNEWLINE " ) ; } if ( powerOf2 ( m ) ) { Console . Write ( " True " ) ; } else { Console . Write ( " False " ) ; } } }