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
what is the height of tree if leaf node is at level 3. please explain
find the output? void r(int a[],int c, int n) { if(c>n) { a[c]=a[c]+c; r(a,++c,n); r(a,++c,n); } } int main() { int i,a[5]={0}; r(a,0,5); for(i=0;i<5;i++) printf("\n %d",a[i]); getch(); }
What do you mean by a local block?
What is difference between class and structure?
What is auto keyword in c?
What are the advantages of c language?
how many errors in c explain deply
what is the difference between 123 and 0123 in c?
What does %p mean c?
Explain high-order and low-order bytes.
What are the 5 organizational structures?
What is assert and when would I use it?
How to throw some light on the b tree?
How can I invoke another program or command and trap its output?
Why do we need volatile in c?