面试题05.07. 配对交换
提取奇数位左移1位, 或上偶数位右移1位.
class Solution {
public int exchangeBits(int num) {
return (((num & 0x55555555) << 1) | ((num & 0xaaaaaaaa) >> 1));
}
}
参考
comments powered by Disqus
提取奇数位左移1位, 或上偶数位右移1位.
class Solution {
public int exchangeBits(int num) {
return (((num & 0x55555555) << 1) | ((num & 0xaaaaaaaa) >> 1));
}
}