result=((n & ((1<<28)/3))<<1)|((n & ((1<<29)/3))>>1);
--
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...@google
first do logical AND of 10101010 with number for masking odd bit shift it
right 1 times suppose it comes n1
first do logical AND of 01010101 with number for masking even bit shift it
left 1 times suppose it come n2
now do n1 || n2
--
You received this message because you are subscribed to the
Mask all odd bits with 10101010 in binary (which is 0xAA), then shift
them left to put them in the even bits. Then, perform a similar
operation for even bits. This takes a total 5 instructions.
int swapOddEvenBits(int x)
{
return ( ((x & 0x) >> 1) | ((x & 0x) << 1) );
}
On No
For 32-bit integers:
result = ((x & 0x) >> 1) | ((x & 0x) << 1);
Dave
On Nov 12, 2:12 am, 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 swap