[algogeeks] Reverse Bits

2011-08-05 Thread rShetty
This is the code to reverse the bits in an unsigned integer . Could anyone please explain the logic of this approach ? Thank You !! #define reverse(x) \ (x=x16|(0xx)16, \ x=(0xff00ff00x)8|(0x00ff00ffx)8, \ x=(0xf0f0f0f0x)4|(0x0f0f0f0fx)4, \ x=(0xx)2|(0xx)2, \

Re: [algogeeks] Reverse Bits

2011-08-05 Thread Nitin Nizhawan
x = x16 | (0xx)16 this line exchanges ls 16bits with ms 16bits, i.e. 1 pair of 16bit this logic of exchanging bits is the used for 2 pairs of 8bits each, then for 4 pairs of 4bit, then for 8 pairs of 2 bit and finally 16 pairs of 1bit. On Fri, Aug 5, 2011 at 6:04 PM, rShetty

Re: [algogeeks] Reverse Bits

2011-08-05 Thread mithun bs
Hi Rajeev, I follow similar approach. The basic logic is swap bits of a pair, then swap nibbles(2 bits) and then swap (4bits), 8bits and go on. So for ex. 0110 1101 1100 0101 In first step, I swap bits of each pair. So this becomes, Input - 0110 1101 1100 0101 output- 1001 1110 1100 1010 In

Re: [algogeeks] Reverse Bits

2011-08-05 Thread rajeev bharshetty
@mithun : Thanks On Fri, Aug 5, 2011 at 6:37 PM, mithun bs mithun...@gmail.com wrote: Hi Rajeev, I follow similar approach. The basic logic is swap bits of a pair, then swap nibbles(2 bits) and then swap (4bits), 8bits and go on. So for ex. 0110 1101 1100 0101 In first step, I swap bits