2010-03-16 28 views
1

基于以下简单的程序,按位左移运算符仅适用于32位。这是真的吗?如何制作64位口罩?

#include <iostream> 
#include <stdlib.h> 

using namespace std; 


    int main(void) 
    { 
     long long currentTrafficTypeValueDec; 
     int input; 
     cout << "Enter input:" << endl; 
     cin >> input; 
     currentTrafficTypeValueDec = 1 << (input - 1); 
     cout << currentTrafficTypeValueDec << endl; 
     cout << (1 << (input - 1)) << endl; 

     return 0; 

    } 

程序的输出:

Enter input: 
30 
536870912 
536870912 

Enter input: 
62 
536870912 
536870912 

我怎么能产生64位掩码?

+0

如果您包含'',这是一个C++问题! – 2010-03-16 09:28:29

+1

除了long long目前不是C++的一部分。 – 2010-03-16 09:30:03

回答

5

使输入也很长,并使用1LL < <(输入 - 1LL)。这里你的班次是在32位上计算的,当存储在currentTrafficTypeValueDec中时转换为64位。