try out with examples!! u will surely get in 2-3 examples N&(N-1) is a very famous expression, used in counting set bits. see what this expression return
On Sat, Jul 2, 2011 at 2:51 PM, cegprakash <cegprak...@gmail.com> wrote: > btw what N = N-(N&(N-1)) does actually > > On Jul 2, 2:11 pm, sunny agrawal <sunny816.i...@gmail.com> wrote: > > for a number N > > first set bit(From Left) is simply integer value of log(N) > > last set bit can be calculated as > > > > N = N-(N&(N-1)); and then Log(N) > > > > int i = log(n); > > n -= n&(n-1); > > int j = log(n); > > > > i-j will be the answer. > > > > On Sat, Jul 2, 2011 at 2:34 PM, cegprakash <cegprak...@gmail.com> wrote: > > > oh fine.. got it now.. set bit is '1' right.. and is there any short > > > ways to find the difference between first set and short set bit > > > without dividing by 2 repeatedly? > > > > > -- > > > 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. > > > > -- > > Sunny Aggrawal > > B-Tech IV year,CSI > > Indian Institute Of Technology,Roorkee > > -- > 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. > > -- Sunny Aggrawal B-Tech IV year,CSI Indian Institute Of Technology,Roorkee -- 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.