根据以下简单的程序按位左移位运算符仅适用于32位。是真的吗?

#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位掩码?

有帮助吗?

解决方案

请输入一个长长太,并使用1LL <<(输入 - 1LL)。这里您的移位计算上32位,并存储在currentTrafficTypeValueDec当转换为64位。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top