Can someone explain how these programs give this result?

int x = -2139062144;  //In binary: 10000000100000001000000010000000
int k = x << 1;

k 16843008(binary :) 1000000010000000100000000, and I do not understand why?

How 10000000100000001000000010000000has it changed to 1000000010000000100000000just one shift of the left bit?

I expected it to be: 10000001000000010000000100000000preservation of the sign, as in the sign of the offset of the right bit.

+4
source share
2 answers

Very simple.

Yours intcan contain no more than 32 bits. Well, exactly 32 bits, all the time.

AT

 10000000100000001000000010000000

the most significant leading bit is 1.

What do you think happens to this doomed bit as a result of a left shift?

Everything has passed. He ceased to exist. He joined the choir invisible. This is an ex-bit.

, , , 0 . ,

00000001000000010000000100000000

:

1000000010000000100000000
+10

All Articles