I have a number X , I want to check the number of powers of 2 it have ? For Ex
N=7 ans is 2 , 2*2
N=20 ans is 4, 2*2*2*2
Similar I want to check the next power of 2
For Ex:
N=14 Ans=16
Is there any Bit Hack for this without using for
loops ?
Like we are having a one line solution to check if it's a power of 2 X&(X-1)==0
,similarly like that ?