Can someone please explain in details why (-3>>0).toString(2)
doesn't return two's complement of 3
in the binary form 11111111111111111111111111111101
, whereas (-3>>>0).toString(2)
returns does?
Both use bit shift, but the former uses Sign-propagating right shift
and latter uses Zero-fill right shift
. I've found this explanation:
-3 >>> 0 (right logical shift) coerces its arguments to unsigned integers, which is why you get the 32-bit two's complement representation of -3.
But I don't know what to make of it. Please provide elaborate answer if possible.