0xa == 0x 1010, which stands for all the even bits 0x5 == 0x 0101, which stands for all the odd bits
>>1 and <<1 means shifting odd to even and even to odd then | means putting new even bits and odd bits together Yanan Cao On Wed, Sep 7, 2011 at 10:23 AM, teja bala <[email protected]>wrote: > > Can anyone plzz xplain the code? > > public static int swapOddEvenBits(int x) { > return ( ((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1) ); > } > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
