Question

Basé sur le programme simple suivant l'opérateur de décalage gauche au niveau du bit ne fonctionne que pour 32 bits. Est-il vrai?

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

    }

La sortie du programme:

Enter input:
30
536870912
536870912

Enter input:
62
536870912
536870912

Comment pourrais-je produire des masques 64 bits?

Était-ce utile?

La solution

Participera une longue trop longtemps, et utiliser 1LL << (entrée - 1LL). Ici, le décalage est calculé sur 32 bits, et converti en 64 bits lorsqu'il est stocké dans currentTrafficTypeValueDec.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top