Bit shifting number gives wrong output `std::cout`
unsigned int command = 4;
cout << command;
command = (command << 1);
cout << command;
command 开发者_开发百科= (command << 1);
cout << command;
Output:
4
8
10
Why is is the output of the last line 10, and not 16?
There's probably a cout << hex somewhere before this code runs. Either that or you accidentally set cout to format numbers in hexadecimal. If you add:
command = (command<<1);
cout << command;
It should print out 20 in hex mode.
10 is hexadecimal for 16.
0x10 == 16
Sorry if I am stating the obvious.
加载中,请稍侯......
精彩评论