unsigned int command = 4;
cout << command;
command = (command << 1);
cout << command;
command = (command << 1);
cout << command;
Run Code Online (Sandbox Code Playgroud)
输出:
4
8
10
Run Code Online (Sandbox Code Playgroud)
为什么是最后一行的输出10,而不是16?
MSN*_*MSN 19
cout << hex在此代码运行之前可能存在某个地方.或者您不小心设置cout为以十六进制格式化数字.如果你添加:
command = (command<<1);
cout << command;
Run Code Online (Sandbox Code Playgroud)
它应该20以十六进制模式打印出来.