Signed right shift with a positive number returns 0
with the following example:
console.log(10 >> 5);
If we continue infinitely doing the same thing, it will always give us 0
:
console.log(10 >> 8);
But if the number is negative when reaching the maximum divisible limit, it returns us -1
instead of zero:
console.log(-10 >> 5);
And if we do it infinitely, it will always return us -1
.
My question is... why in the last case the value returned is always -1
when the division limit is reached??, shouldn't it be 0
the same as in the case where the number is positive?
If you try with both negative numbers, the same thing happens:
console.log(-10 >> -8);
I know that it doesn't make sense that you can shift to the right in a negative way, but in this case it also continues to return -1
and not 0
or by default -10
it was the original number, why does this happen?
That is to say, I would understand that it returned -10
in case it did not make any displacement, but in this case when returning a number different from the original I feel that even so a displacement is being made.