Find if a number is power of two or not?



Find if a number is power of two or not?..

Answer / om

int f(int num)
{

if(( num>0) && (!(num & (num-1))) )
return 1;
else
return 0;
}
// f(16)...... 16 & 15 = 10000 & 01111 =00000
f(4) ...... 4 & 3 =0100 & 0111 =0000

f(11).......11 & 10 = 1011 & 1010 = 1010 so not...
f(12).......12 & 11 = 1100 & 1011 = 1000 so not...

Is This Answer Correct ?    6 Yes 0 No

Post New Answer

More C Interview Questions

Please send me WIPRO technical question to my mail ID.. its nisha_g28@yahoo.com please its urgent

0 Answers  


What is c method?

0 Answers  


int array[]={1,2,3,4,5,6,7,8}; #define SIZE (sizeof(array)/sizeof(int)) main() { if(-1<=SIZE) printf("1"); else printf("2"); }

2 Answers   Vector,


Can we use any name in place of argv and argc as command line arguments?

0 Answers  


What is the scope of static variable in c?

0 Answers  






How does sizeof know array size?

0 Answers  


In c programming language, how many parameters can be passed to a function ?

0 Answers  


Why is #define used?

0 Answers  


what is pointer?

13 Answers   HCL, TCS,


What is selection sort in c?

0 Answers  


why Language C is plateform dependent

3 Answers   Siemens, Wipro,


in programming languages a statement or part of a statement that specifies several different execution sequences a) constructs b) distructs c) executes d) none

0 Answers  


Categories