Skip to content

Commit f81230e

Browse files
Merge pull request matthewsamuel95#140 from shivansh/isPowerOf4
[Bit Manipulation] Check if a given number is a power of 4
2 parents de6f2b8 + d685b4b commit f81230e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
bool isPowerOfFour(int num) {
5+
return (num > 0) && !(num & (num - 1)) && !((num - 1) % 3);
6+
}
7+
8+
int main() {
9+
cout << isPowerOfFour(64) << endl;
10+
return 0;
11+
}

0 commit comments

Comments
 (0)