Re: [algogeeks] Re: Bit Twiddles

2011-07-11 Thread rajeev bharshetty
@Dave Got It Thanks On Tue, Jul 12, 2011 at 1:23 AM, SkRiPt KiDdIe wrote: > Got it :) > > > On Tue, Jul 12, 2011 at 1:18 AM, Dave wrote: > >> @SkRiPt: Yes. >> >> Dave >> >> On Jul 11, 2:43 pm, SkRiPt KiDdIe wrote: >> > are you saying that x finally contains the number of bits that are set >

Re: [algogeeks] Re: Bit Twiddles

2011-07-11 Thread SkRiPt KiDdIe
Got it :) On Tue, Jul 12, 2011 at 1:18 AM, Dave wrote: > @SkRiPt: Yes. > > Dave > > On Jul 11, 2:43 pm, SkRiPt KiDdIe wrote: > > are you saying that x finally contains the number of bits that are set to > > 1..?? > > > > > > > > On Tue, Jul 12, 2011 at 1:09 AM, Dave wrote: > > > @rShetty:

Re: [algogeeks] Re: Bit Twiddles

2011-07-11 Thread SkRiPt KiDdIe
on executing the code : #include using namespace std; int main() { int x=0x4000; x = (x & 0x) + ((x >> 1) & 0x); cout< wrote: > @SkRiPt: Yes. > > Dave > > On Jul 11, 2:43 pm, SkRiPt KiDdIe wrote: > > are you saying that x finally contains the number

[algogeeks] Re: Bit Twiddles

2011-07-11 Thread Dave
@SkRiPt: Yes. Dave On Jul 11, 2:43 pm, SkRiPt KiDdIe wrote: > are you saying that x finally contains the number of bits that are set to > 1..?? > > > > On Tue, Jul 12, 2011 at 1:09 AM, Dave wrote: > > @rShetty: Ask a question. What do you need to know? > > > Dave > > > On Jul 11, 1:26 pm, rShet

Re: [algogeeks] Re: Bit Twiddles

2011-07-11 Thread SkRiPt KiDdIe
are you saying that x finally contains the number of bits that are set to 1..?? On Tue, Jul 12, 2011 at 1:09 AM, Dave wrote: > @rShetty: Ask a question. What do you need to know? > > Dave > > On Jul 11, 1:26 pm, rShetty wrote: > > Some more Explanation of the working would be helpful > > > > Th

[algogeeks] Re: Bit Twiddles

2011-07-11 Thread Dave
@rShetty: Ask a question. What do you need to know? Dave On Jul 11, 1:26 pm, rShetty wrote: > Some more Explanation of the working would be helpful > > Thank You .. > > On Jul 11, 11:11 pm, Dave wrote: > > > > > Assuming that the integer is 32 bits, this is pretty good: > > > x = (x & 0x555

[algogeeks] Re: Bit Twiddles

2011-07-11 Thread rShetty
Some more Explanation of the working would be helpful Thank You .. On Jul 11, 11:11 pm, Dave wrote: > Assuming that the integer is 32 bits, this is pretty good: > > x = (x & 0x) +  ((x >> 1) & 0x); > x = (x & 0x) +  ((x >> 2) & 0x); > x = (x & 0x0F0F0F0F) +  ((x >

[algogeeks] Re: Bit Twiddles

2011-07-11 Thread Dave
Assuming that the integer is 32 bits, this is pretty good: x = (x & 0x) + ((x >> 1) & 0x); x = (x & 0x) + ((x >> 2) & 0x); x = (x & 0x0F0F0F0F) + ((x >> 4) & 0x0F0F0F0F); x = (x & 0x00FF00FF) + ((x >> 8) & 0x00FF00FF); x = (x & 0x) + ((x >> 16) & 0x