Program to find whether a given number is power of 2 | 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
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 " ) ; } } }