-2
's one's complement is 100000...01
-2
's two's complement is 1000000...10
-2 >>> 1
According >>>
definition left side shifts in 0
should be something like 01000......1
, why becomes 0111111..11
?
-2
's one's complement is 100000...01
-2
's two's complement is 1000000...10
-2 >>> 1
According >>>
definition left side shifts in 0
should be something like 01000......1
, why becomes 0111111..11
?
Copyright © 2021 Jogjafile Inc.
In order to produce two's complement representation of
2
(i.e.-2
's representation) you start with the representation of2
, flip all its bits, and add1
to the result:-2
's binary representation is11111111111111111111111111111110
(demo).Shifting it over to the right by one without sign-extension produces
which is precisely the result that you get.