Domanda

Sulla base del seguente programma semplice la sinistra bit a bit operatore di spostamento funziona solo per 32 bit. E 'vero?

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

    }

L'output del programma:

Enter input:
30
536870912
536870912

Enter input:
62
536870912
536870912

Come potrei produrre maschere a 64 bit?

È stato utile?

Soluzione

Fai ingresso una lunga lunga troppo, e utilizzare 1LL << (ingresso - 1LL). Qui il turno è calcolata su 32 bit, e convertito a 64 bit se conservate in currentTrafficTypeValueDec.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top