Write a program to swap odd and even bits in an integer with as few instructions as possible.
public static int swapOddEvenBits(int x) { return ( (( x & 0xaaaaaaaa) >> 1 | (x & 0x55555555) << 1) ); }
时间: 2024-11-08 12:28:32
Write a program to swap odd and even bits in an integer with as few instructions as possible.
public static int swapOddEvenBits(int x) { return ( (( x & 0xaaaaaaaa) >> 1 | (x & 0x55555555) << 1) ); }