Skip to content

Commit

Permalink
write function to check if a number is a power of two in cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
justanindieguy committed Jan 30, 2023
1 parent 2c92fe8 commit d9246ed
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Bit-manipulationTechniques/TwoPower/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <iostream>

using namespace std;

void isPowerOfTwo(int n)
{
if ((n & (n - 1)) == 0)
{
cout << "Power of two" << endl;
}
else
{
cout << "Not a power of two" << endl;
}
}

int main()
{
int n = 5;
isPowerOfTwo(n);

return 0;
}

0 comments on commit d9246ed

Please sign in to comment.