Determine if a number is a power of 2 at O(1).

Answers were Sorted based on User's Feedback



Determine if a number is a power of 2 at O(1)...

Answer / hary

int Isnopowerof2(int n)
{
if (n & n-1)
return 0;
return 1;
}

Is This Answer Correct ?    15 Yes 0 No

Determine if a number is a power of 2 at O(1)...

Answer / srinu naik

if((~n+1)& n ==n) printf("\n Given number is power of 2");
else printf("\Not the POwer of 2");

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More C Interview Questions

while loop contains parts a) initialisation, evalution of an expression,increment /decrement b) initialisation, increment/decrement c) condition evalution d) none of the above

0 Answers  


Write code for finding depth of tree

2 Answers   Adobe,


What is a string?

0 Answers  


Explain what is the benefit of using #define to declare a constant?

0 Answers  


application of static variables in real time

1 Answers   Bosch,






How can I call system when parameters (filenames, etc.) Of the executed command arent known until run time?

0 Answers  


Write a program to swap two numbers without using third variable in c?

0 Answers  


please send me papers for Dy. manager IT , PNB. it would be a great help for me.

0 Answers  


What is the 'named constructor idiom'?

0 Answers  


What does sizeof function do?

0 Answers  


pascal triangle program

2 Answers  


If I have a char * variable pointing to the name of a function ..

0 Answers  


Categories