mockers
Would you like to react to this message? Create an account in a few clicks or log in to continue.

no power of 2

3 posters

Go down

no power of 2 Empty no power of 2

Post  shivang Mon Feb 02, 2009 3:40 am

Find whether a no is power of 2?
shivang
shivang

Posts : 42
Join date : 2009-01-30
Age : 35

Back to top Go down

no power of 2 Empty Re: no power of 2

Post  $corpion Mon Feb 02, 2009 4:03 am

if no>1 and count of no of bits as 1 is one..den its power of 2...
is it k??
$corpion
$corpion

Posts : 25
Join date : 2009-01-30
Age : 37

Back to top Go down

no power of 2 Empty Re: no power of 2

Post  shivang Mon Feb 02, 2009 4:04 am

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)
shivang
shivang

Posts : 42
Join date : 2009-01-30
Age : 35

Back to top Go down

no power of 2 Empty Re: no power of 2

Post  udita Mon Feb 02, 2009 8:48 am

if x is a power of two then x & (x-1)==0
according to me this will work for all integers

udita

Posts : 11
Join date : 2009-02-01

Back to top Go down

no power of 2 Empty Re: no power of 2

Post  shivang Mon Feb 02, 2009 9:51 am

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..... cheers

the correct solution is

if
( !(x&(x-1))& x) !=0
then power of 2


thats wat mistake i made in the interview.... cheers
shivang
shivang

Posts : 42
Join date : 2009-01-30
Age : 35

Back to top Go down

no power of 2 Empty Re: no power of 2

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum