+ 1

Powerof2

What are power of 2? And how to check if the number is power of2?

10th Mar 2018, 6:55 PM
Ghaida
Ghaida - avatar
2 ответов
+ 12
divide the number by 2 repeatedly if n%2 comes out to be 0 //if n comes out to be 1 at last , then it is 2^x form else its not 2^x form
10th Mar 2018, 7:23 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 4
technically everything is a power of 2(instead of negative numbers[not talking about complex numbers]) to find the power Use log and check if the result is an integer. if it is then its a power of 2(2^1,2^2,...2^n) while n is an integer. otherwise its not an integer
10th Mar 2018, 7:08 PM
Tomer Sim
Tomer Sim - avatar