I'm writing a left shift algorithm in Java and have been doing some left shift calculations by hand. All of these numbers are typed as byte, btw.
Let's say I'm working with 8-bit integers from -128 to 127.
Then from my calculations:
(-113 << 4) == (-65 << 4) == -16
because
-113 == 1 0 0 0 1 1 1 1
-113 << 4 == 1 1 1 1 0 0 0 0 == -16
but so does
-65 == 1 0 1 1 1 1 1 1
-65 << 4 == 1 1 1 1 0 0 0 0 == -16
So left shifting -113 by 4 and left shifting -65 by 4 result in the same value? Shouldn't all left shift operations produce unique values? Or do I have this right?
EDIT:
I'm working in Java and all of my numbers are bytes and the JVM is throwing an "error: loss of precision error" and this is what is also precipitating my question. Thanks!