Give a oneline C expression to test whether a number is a
power of 2?
Answers were Sorted based on User's Feedback
Answer / dan
if (x & (x-1)) // false only if x is a power of 2
| Is This Answer Correct ? | 102 Yes | 8 No |
Answer / ashutosh
I think
if (x & (x-1)) wont work when number is negative.
| Is This Answer Correct ? | 12 Yes | 10 No |
Answer / fjords
if (int(log(x)) == log(x)) // log is to the base 2
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / rahul priyadarshi
#define ISPOW2(x) ((x==1)?1:(x&(x-1)))?0:1
| Is This Answer Correct ? | 1 Yes | 0 No |
Answer / yevgen
if ((num XOR (num - 1)) == num + num - 1) return true;
else return false;
| Is This Answer Correct ? | 1 Yes | 0 No |
Predict the Output: int main() { int *p=(int *)2000; scanf("%d",2000); printf("%d",*p); return 0; } if input is 20 ,what will be print
what will be the position of the file marker? a: fseek(ptr,0,SEEK_SET); b: fseek(ptr,0,SEEK_CUR);
What is the main difference between STRUCTURE and UNION?
posted by surbhi just now main() { float a = 5.375; char *p; int i; p=(char*)&a; for(i=0;i<=3;i++) printf("%02x",(unsigned char) p[i]); } how is the output of this program is :: 0000ac40 please let me know y this output has come
write a program in c to merge two array
#ifdef something int some=0; #endif main() { int thing = 0; printf("%d %d\n", some ,thing); }
main() { char c; int i = 456; clrscr(); c = i; printf("%d", c); } a. 456 b. -456 c. random number d. none of the above
#define SQR(x) x * x main() { printf("%d", 225/SQR(15)); } a. 1 b. 225 c. 15 d. none of the above
main() { if (!(1&&0)) { printf("OK I am done."); } else { printf("OK I am gone."); } } a. OK I am done b. OK I am gone c. compile error d. none of the above
String copy logic in one line.
main() { int i = 258; int *iPtr = &i; printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) ); }
how to check whether a linked list is circular.