如何制作64位掩码?

use*_*167 2 c++ 64-bit bitmask bit-shift

基于以下简单程序,按位左移运算符仅适用于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;

    }
Run Code Online (Sandbox Code Playgroud)

该计划的输出:

Enter input:
30
536870912
536870912

Enter input:
62
536870912
536870912
Run Code Online (Sandbox Code Playgroud)

我怎么能生产64位掩码?

Eri*_*lle 6

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