2

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

4

1 回答 1

6

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

于 2010-03-16T09:31:54.533 回答