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 rajeevr...@gmail.com wrote:

 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, \
 x=(0xx)1|(0xx)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.



-- 
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.



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 second step, I swap 2bits

Input - 1001 1110 1100 1010
output-0110 1011 0011 1010

I swap 4 bits now

Input - 0110 1011 0011 1010
output-1011 0110 1010 0011

Now I swap 8bits
Input - 1011 0110 1010 0011
output-1010 0011 1011 0110

So, now we have the bits in reverse order.

First step I do this way
x = ((x | 0x)  2) | (x2) | 0x;
Next step similarly
x = ((x | 0x)  4) | (x4) | 0x;

This is the logic.
Your code does the reverse way.

Regards,
Mithun

On Fri, Aug 5, 2011 at 6:04 PM, rShetty rajeevr...@gmail.com wrote:

 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, \
 x=(0xx)1|(0xx)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.




-- 
Mithun.B.S
M:9916775380

-- 
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.



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 of each pair. So this becomes,

 Input -  0110 1101 1100 0101
 output- 1001 1110 1100 1010

 In second step, I swap 2bits

 Input - 1001 1110 1100 1010
 output-0110 1011 0011 1010

 I swap 4 bits now

 Input - 0110 1011 0011 1010
 output-1011 0110 1010 0011

 Now I swap 8bits
 Input - 1011 0110 1010 0011
 output-1010 0011 1011 0110

 So, now we have the bits in reverse order.

 First step I do this way
 x = ((x | 0x)  2) | (x2) | 0x;
 Next step similarly
 x = ((x | 0x)  4) | (x4) | 0x;

 This is the logic.
 Your code does the reverse way.

 Regards,
 Mithun

 On Fri, Aug 5, 2011 at 6:04 PM, rShetty rajeevr...@gmail.com wrote:

 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, \
 x=(0xx)1|(0xx)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.




 --
 Mithun.B.S
 M:9916775380

  --
 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.




-- 
Regards
Rajeev N B http://www.opensourcemania.co.cc

*Winners Don't do Different things , they do things Differently*

-- 
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.