+ 1
Tell reason of output 2. When this code runs:
#include <iostream> using namespace std; int main() { cout<<(1<<1); return 0; }
4 Answers
+ 9
Tip:
Left Shift by 1 = Multiplication by 2
Right Shift by 1 = Division by 2
+ 4
In binary.
00000001
<< ( left shift ) one step
the result will be
00000010 ( 2 )
+ 1
that implies <<<< =multiply 4
+ 1
not at all.
let's the variable is declared as 8bit signed integer. ( byte )
the first bit is signed bit.
(0)100 0000 = 64
64 << 1 = (1)000 0000 = -128
according to the C Language standard.
The "byte" must be 8 bit.
you may declare it as unsigned (0-255).
for the type "int".
it is depends on the OS and the CPU.
Nowadays, it's usually 64bit length.
For Java, the int must be 32bit signed.
( Java can not unsigned )