如何生成64位掩码?

发布于 2024-08-25 19:59:57 字数 660 浏览 3 评论 0原文

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

Based on the following simple program the bitwise left shift operator works only for 32 bits. Is it true?

#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;

    }

The output of the program:

Enter input:
30
536870912
536870912

Enter input:
62
536870912
536870912

How could I produce 64-bit masks?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

二手情话 2024-09-01 19:59:58

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

Make input an long long too, and use 1LL << (input - 1LL). Here your shift is computed on 32 bits, and converted to 64 bits when stored in currentTrafficTypeValueDec.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文