您的位置:首页 > 其它

取一个数的第i位

2016-05-14 20:41 176 查看
运用了一个函数,将X移i位,得到的数和1做位与运算,得到的就是X的第i位
#include <iostream>

using namespace std;
typedef unsigned long long ull;
ull bits(ull x,int i)
{
return (x >> i) & 1ULL;
}
int main()
{
int testCase,i;
while (cin>>testCase>>i)
{
cout<<bits(testCase,i)<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: