For 32-bit integers:

result = ((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1);

Dave

On Nov 12, 2:12 am, sudhir mishra <sudhir08.mis...@gmail.com> 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
>
>  B60.gif
> < 1KViewDownload

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

Reply via email to