开发者

How to produce 64 bit masks?

开发者 https://www.devze.com 2022-12-23 15:23 出处:网络
Based on the following simple program the bitwise left shift operator works only for 32 bits. Is it true?

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号