문제

다음 간단한 프로그램을 기반으로 비트 왼쪽 시프트 연산자는 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 << (입력 -1ll)을 사용하십시오. 여기서 교대는 32 비트로 계산되며 CurrentTrafficTyPevaluedec에 저장 될 때 64 비트로 변환됩니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top