请参阅下面的简单代码:
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(void)
{
unsigned long currentTrafficTypeValueDec;
long input;
input=63;
currentTrafficTypeValueDec = (unsigned long) 1LL << input;
cout << currentTrafficTypeValueDec << endl;
printf("%u \n", currentTrafficTypeValueDec);
printf("%ld \n", currentTrafficTypeValueDec);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么printf()显示带负值的currentTrafficTypeValueDec(unsigned long)?
输出是:
9223372036854775808
0
-9223372036854775808
Run Code Online (Sandbox Code Playgroud) 基于以下简单程序,按位左移运算符仅适用于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;
}
Run Code Online (Sandbox Code Playgroud)
该计划的输出:
Enter input:
30
536870912
536870912
Enter input:
62
536870912
536870912
Run Code Online (Sandbox Code Playgroud)
我怎么能生产64位掩码?