面试题 05.07. 配对交换 Posted on 2021-07-26 Edited on 2022-11-27 In leetcode Disqus: Symbols count in article: 231 Reading time ≈ 1 mins. 面试题 05.07. 配对交换 偶数位左移1,奇数位右移1. 12345678class Solution {public: int exchangeBits(int num) { int odd = num & 0xaaaaaaaa; // 1010...1010,提取奇数位 int even = num & 0x55555555; // 0101...0101,提取偶数位 return (even << 1) | (odd >> 1); }};