我正在运行以下程序:(URL:http://ideone.com/aoJoI5)
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
long long int N=pow(2, 36);
cout << N <<endl;
int count = 0;
cout << "Positions where bits are set : " << endl;
for(int j=0; j<sizeof(long long int)*8; ++j){
if(N&(1<<j)){
++count;
cout << j << endl;
}
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这个程序给我输出为:
68719476736
Positions where bits are set :
31
63
Run Code Online (Sandbox Code Playgroud)
现在我正在使用N = 2 ^ 36,这意味着第36位应该是1而没有别的,但为什么程序给我位置31和63?我的程序有什么问题吗?
我有一个观察结果,如果我们使用N = 2 ^ {exp},其中exp> = 32,它总是给出设置位的位置为31和63.任何人都可以解释为什么会发生这种情况?
c++ ×1