/*用0xAAAAAAAA与x相与求的奇数位上数字(偶数位上数字为0) 用0x 55555555 与x相与求的偶数位上数字(奇数位上数字为0) oddVal右移一位 even左移一位相加即可。*/ class Exchange { public: int exchangeOddEven(int x) { // write code here int oddVal = (x & 0xAAAAAAAA); // bit 1 3 5 ... 31 int evenVal = (x & 0x55555555); // bit 0 2 4 ... 30 return (oddVal >> 1) + (evenVal << 1); } };