no power of 2
3 posters
Page 1 of 1
Re: no power of 2
if no>1 and count of no of bits as 1 is one..den its power of 2...
is it k??
is it k??
$corpion- Posts : 25
Join date : 2009-01-30
Age : 37
Re: no power of 2
if no>1....ke liye to sahi hai....
one line answer de.....chekin all the conditions....i.e working for all the intergers(not negative)
one line answer de.....chekin all the conditions....i.e working for all the intergers(not negative)
shivang- Posts : 42
Join date : 2009-01-30
Age : 35
Re: no power of 2
if x is a power of two then x & (x-1)==0
according to me this will work for all integers
according to me this will work for all integers
udita- Posts : 11
Join date : 2009-02-01
Re: no power of 2
hey admin....y deleted my post.....
try x&(x-1) for 0...it will giv 0.....which will show that 0 is also a power of 2.....
the correct solution is
if
( !(x&(x-1))& x) !=0
then power of 2
thats wat mistake i made in the interview....
try x&(x-1) for 0...it will giv 0.....which will show that 0 is also a power of 2.....
the correct solution is
if
( !(x&(x-1))& x) !=0
then power of 2
thats wat mistake i made in the interview....
shivang- Posts : 42
Join date : 2009-01-30
Age : 35
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|