A
A
annozzer2015-09-08 19:09:30
Programming
annozzer, 2015-09-08 19:09:30

Is a number a power of two in c++ without using if?

I write
return a && (a & (a - 1)) == 0);
it seems to help, but how to make it so that if it is a degree, "+" or "true" is written without if,
or what error is in the code.
#include
#include
using namespace std;
int main
{
int a;
cin >> a;
return a && (a & (a - 1)) == 0);
return 0;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Kononenko, 2015-09-08
@annozzer

cout << a && (a & (a - 1)) == 0);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question