[algogeeks] Re: Cisco Question

2011-06-27 Thread rShetty
@Dave Thank You very much :) On Jun 27, 8:48 pm, piyush kapoor wrote: > thanks a lot for the wonderful explanation :-) > > > > > > > > > > On Mon, Jun 27, 2011 at 7:17 PM, Dave wrote: > > @Rajeev and Piyush: Numbering the bits from the right starting with 0 > > as usual, you see that you need to

Re: [algogeeks] Re: Cisco Question

2011-06-27 Thread piyush kapoor
thanks a lot for the wonderful explanation :-) On Mon, Jun 27, 2011 at 7:17 PM, Dave wrote: > @Rajeev and Piyush: Numbering the bits from the right starting with 0 > as usual, you see that you need to move the even-numbered bits one bit > to the left and the odd-numbered bits one bit to the righ

[algogeeks] Re: Cisco Question

2011-06-27 Thread Dave
@Rajeev and Piyush: Numbering the bits from the right starting with 0 as usual, you see that you need to move the even-numbered bits one bit to the left and the odd-numbered bits one bit to the right. You could do this one bit-pair at a time, but it would be more efficient if you could do all pairs

Re: [algogeeks] Re: Cisco Question

2011-06-27 Thread piyush kapoor
Yep,I also want to know the same.. On Mon, Jun 27, 2011 at 6:23 PM, rajeev bharshetty wrote: > @ Dave How to think about the answer to the above question . I mean How do > I tackle such problems ? > > > On Mon, Jun 27, 2011 at 6:17 PM, Dave wrote: > >> y = ((x & 0x55) << 1) | ((x >> 1) & 0x55).

Re: [algogeeks] Re: Cisco Question

2011-06-27 Thread rajeev bharshetty
@ Dave How to think about the answer to the above question . I mean How do I tackle such problems ? On Mon, Jun 27, 2011 at 6:17 PM, Dave wrote: > y = ((x & 0x55) << 1) | ((x >> 1) & 0x55). > > Note, 0x55 = 01010101 in binary. > > Dave > > On Jun 27, 7:18 am, rShetty wrote: > > Given a byte, wr

[algogeeks] Re: Cisco Question

2011-06-27 Thread Dave
y = ((x & 0x55) << 1) | ((x >> 1) & 0x55). Note, 0x55 = 01010101 in binary. Dave On Jun 27, 7:18 am, rShetty wrote: > Given a byte, write a code to swap every two bits. [Using bit > operators] > >  Eg: Input: 10 01 11 01 Output: 01 10 11 10 -- You received this message because you are subscri