Logarithm tricks for Competitive Programming | C # implementation to check that a integer is a power of Two ; Function to check if the number is a power of two ; Driver Code
using System ; class GFG { public static bool isPowerOfTwo ( int n ) { return ( Math . Ceiling ( Math . Log ( n ) / Math . Log ( 2 ) ) == Math . Floor ( Math . Log ( n ) / Math . Log ( 2 ) ) ) ; } public static void Main ( String [ ] args ) { int N = 8 ; if ( isPowerOfTwo ( N ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } }