one more condition is required if(num != 0 && !( num & (num-1))
On Sat, Aug 20, 2011 at 4:04 PM, Sanjay Rajpal <[email protected]> wrote: > if(!(x & x-1)) printf("No. is power of 2"); > > > Sanju > :) > > > > On Sat, Aug 20, 2011 at 3:32 AM, Abhishek Yadav < > [email protected]> wrote: > >> Give a one-line C expression to test whether a number is a power of 2. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> >> > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
