@sandeep number which is a power of 2 only one bit will be set. number -1 : all the bits except the one which was set at num with be 1 so num & num-1 will be 0 coz of bitwise and
On Sat, Aug 20, 2011 at 4:15 PM, SANDEEP CHUGH <sandeep.aa...@gmail.com>wrote: > explain it plz > > > On Sat, Aug 20, 2011 at 4:09 PM, Abhishek Yadav < > algowithabhis...@gmail.com> wrote: > >> got it ...thanks >> >> >> On Sat, Aug 20, 2011 at 4:04 PM, Sanjay Rajpal <srn...@gmail.com> wrote: >> >>> if(!(x & x-1)) printf("No. is power of 2"); >>> >>> >>> Sanju >>> :) >>> >>> >>> >>> On Sat, Aug 20, 2011 at 3:32 AM, Abhishek Yadav < >>> algowithabhis...@gmail.com> 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 algogeeks@googlegroups.com. >>>> To unsubscribe from this group, send email to >>>> algogeeks+unsubscr...@googlegroups.com. >>>> 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 algogeeks@googlegroups.com. >>> To unsubscribe from this group, send email to >>> algogeeks+unsubscr...@googlegroups.com. >>> 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 algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> 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 algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.