javascript - >>> (Zero-fill right shift) when second oprand is zero -
i understand zero-fill right shift , results yields make perfect sense when second operand non-zero:
-7 >>> 1 2147483644
compare with
-7 >> 1 -4
but when second operand zero:
-7 >> 0 -7 // looks right! -7 >>> 0 4294967289 // what? why?
if i'm shifting 0 bits, doesn't mean i'm not shifting @ all? if that's case, shouldn't give me original number? expect -7 >>> 0 === -7
and also
-7 >>> 32 4294967289
again, definition, expect -7 >>> n === 0 n >= 32
because digits become zeros!
found internal workings of in specs.
x >>> 0
touint32(x)
and
7.1.6 touint32 ( argument )
the abstract operation touint32 converts argument 1 of 232 integer values in range 0 through 232−1, inclusive. abstract operation functions follows: let number tonumber(argument). returnifabrupt(number). if number nan, +0, −0, +∞, or −∞, return +0. let int mathematical value same sign number , magnitude floor(abs(number)). let int32bit int modulo 232. return int32bit.
note let int32bit int modulo, and
the notation “x modulo y” (y must finite , nonzero) computes value k of same sign y (or zero) such abs(k) < abs(y) , x−k = q × y integer q.
so above convention, -7 mod 2^32 === 2^32 - 7 === 4294967289
Comments
Post a Comment