jasonpogi1669

Checking if a Number is a Power of 2 using C++

Dec 15th, 2021 (edited)
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.23 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     ios::sync_with_stdio(false);
  7.     cin.tie(0);
  8.     int n;
  9.     cin >> n;
  10.     bool checker = n && (!(n & (n - 1)));
  11.     cout << (checker ? "YES" : "NO") << '\n';
  12.     return 0;
  13. }
  14.  
Add Comment
Please, Sign In to add comment