what is the purpose of the code, and is there any problem
with it.
bool f( uint n )
{ return (n & (n-1)) == 0; }
Answer Posted / c.p.senthil
function returns if the number is a power of 2. if number value is 1, 2, 4, 8, 16 ... then TRUE is returned.
f(1) => 1 & 0 => 0001 & 0000 => 0
f(2) => 2 & 1 => 0010 & 0001 => 0
f(3) => 3 & 2 => 0011 & 0010 => 1 (non zero) => return true
f(4) => 4 & 3 => 0100 & 0011 => 0
f(5) => 5 & 4 => 0101 & 0100 => 4 (non zero) => return true
f(6) => 6 & 5 => 0110 & 0101 => 4 (non zero) => return true
f(7) => 7 & 6 => 0111 & 0110 => 6 (non zero) => return true
f(8) => 8 & 7 => 1000 & 0111 => 0
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
Can we access array using pointer in c language?
What is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?
What is modeling?
What is the difference between array and structure in c?
What are the different file extensions involved when programming in C?
What do you understand by friend-functions? How are they used?
How can I generate floating-point random numbers?
What is fflush() function?
Explain what is page thrashing?
What are the application of void data type in c?
write a program to find out prime number using sieve case?
write a C program:There is a mobile keypad with numbers 0-9 and alphabets on it. Take input 0f 7 keys and then form a word from the alphabets present on the keys.
write a program that declares an array of 30 elements named "income" in the main functions. then cal and pass the array to a programmer-defined function named "getIncome" within the "getIncome" function, ask the user for annual income of 30 employees. then calculate and print total income on the screen using the following function: "void getIncome ( ai []);
What is openmp in c?
Which is the memory area not included in C program? give the reason