In the operator shift, the sign of the bit is ignored. So 1 1,000,000 <1 is 10,000,000, which is -128.what is the problem?
Our machines use two additions to represent numbers (signed and unsigned). To represent a negative machine, a number negates a positive value and adds 1.
-128 is! 10000000 + 1 = 01111111 + 1 = 10000000
EDIT:
I was wrong, only the shift-shift operator ignored the sign bit. 10100000 <1 == 01000000
For unsigned offsets, there is a โ> operator on the right, which also shifts the sign bit.
11000000 โ 1 == 10100000 and 11000000 โ> 1 == 01100000
source share