check number is power of 2 or not

given n=200
Check this number is power of two or not

Solution:

1 |  01
2 |  10
3 |  011
4 |  100
5 |  101
6 |  110
7 |  0111
8 |  1000

Check the binary digit of the number with power 

if we do n&n-1, Result will be 0

so, n&n-1 result is not 0, then that number not a power of two

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation