

题目
解决代码及点评
/*
将一个数中的偶数位 bit 和奇数位 bit 交换
*/
#include <iostream>
using namespace std;
int SwapOddEvenBits(int n)
{
return ((n&0xaaaaaaaa)>>1) | ((n&0x55555555) << 1);
}
int main()
{
cout<<SwapOddEvenBits(21)<<endl;
system("pause");
return 0;
}
代码下载及其运行
代码下载地址:http://download.youkuaiyun.com/detail/yincheng01/6704519
解压密码:c.itcast.cn
下载代码并解压后,用VC2013打开interview.sln,并设置对应的启动项目后,点击运行即可,具体步骤如下:
1)设置启动项目:右键点击解决方案,在弹出菜单中选择“设置启动项目”
2)在下拉框中选择相应项目,项目名和博客编号一致
3)点击“本地Windows调试器”运行
程序运行结果