Write a program to swap odd and even bits in an integer with as few instructions as possible.
(CC 5.5)
面fuhu 碰到原题
public static int swapOddEvenBits (int x) {
//your code
}
public static int swapOddEvenBits (int x) {
return(((x&0xaaaaaaaa)>>1)|((x&0x55555555)<<1));
}