c++ - 如何生成 64 位掩码?

标签 c++ 64-bit bit-shift bitmask

基于以下简单程序,按位左移运算符仅适用于 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 << (input - 1LL)。此处您的类次是按 32 位计算的,并在存储在 currentTrafficTypeValueDec 中时转换为 64 位。

关于c++ - 如何生成 64 位掩码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2453189/

相关文章:

c++ - 与引用 lambda 崩溃异步

C++:在不禁用 UAC 的情况下截取 Windows 登录屏幕/UAC 提示

c++ - 如何链接两个 LLVM 位码模块?

python - matplotlib 的 xkcd() 不工作

c++ - 在 C++ 中附加两个无符号字符的位运算符

c# - 是否可以编译使用 .NET DLL 和 GCC 的 C++?

c++ - Windows 64位共享dll Tesseract?

C# - 如何在 Windows 64 位上获取程序文件 (x86)

c - 请为我解释这个二进制搜索功能

Javascript 到 Python,在 for 循环的条件和最终表达式中按位移位