Hii Can anyone explain to me what this code is doing?? On 17 May 2012 20:36, Ashish Goel <ashg...@gmail.com> wrote:
> got it...super... > > > Best Regards > Ashish Goel > "Think positive and find fuel in failure" > +919985813081 > +919966006652 > > > On Thu, May 17, 2012 at 8:21 PM, Ashish Goel <ashg...@gmail.com> wrote: > >> Hello Dave, >> >> Was trying this >> >> bool OnesZerosOnes(unsigned int n) >> { >> if( !(n & 1) || !(n &= n+1) ) return 0; /*step1*/ >> n |= n-1;/*step 2*/ >> return !(n & (n+1)); /*step 3*/ >> } >> >> >> for 1110011 >> after step 1 it becomes 1110011&1110100=1110000 >> after step2 it becomes 1110000|1101111=1111111(all ones) >> on step 3 we return~(1111111&0000000) = 1 >> >> for 1010011 >> after step 1 it becomes 1010011&1010100=1010000 >> after step2 it becomes 1010000|1001111=1011111 >> on step 3 we return~(1011111&1100000) = 0 >> >> >> what are we trying to do with step 3 here >> >> Best Regards >> Ashish Goel >> "Think positive and find fuel in failure" >> +919985813081 >> +919966006652 >> >> >> On Sat, Apr 7, 2012 at 11:24 AM, Dave <dave_and_da...@juno.com> wrote: >> >>> bool OnesZerosOnes(unsigned int n) >>> { >>> if( !(n & 1) || !(n &= n+1) ) return 0; >>> n |= n-1; >>> return !(n & (n+1)); >>> } >>> >> >> > -- > 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. > -- *Piyush Khandelwal*** Mobile No: 91-8447229204 91-9808479765 -- 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.