(((x & 0xaaaaaaaa)>>1) | ((x & 0x55555555)<<1)) 5 bit operations in total.
On 2010-11-12 16:12, sudhir mishra wrote:
Write a program to swap odd and even bits in an unsigned integer with as few instructions as possible (e.g., bit 0 and bit 1 are swapped, bit 2 and bit 3 are swapped, etc).eg.... input--- 1234567 7654321 888 output-- 2222411 12109682 948 -- regards /*Sudhir Mishra*/ MNNIT ALLAHABAD --You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group.To post to this group, send email to algoge...@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 algoge...@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.
<<image/gif>>