I have this piece of javascript code that I am trying to understand
return ( n >>> 0 ) * 2.34e10;
So what does >>> mean?
And thanks in advance ... this is my first question on SO
It's a zero-fill right shift. This won't do anything to positive whole numbers or 0, but it does funny things on negative numbers (because the most significant bit changes to zero).
2 >>> 0 === 2
1 >>> 0 === 1
0 >>> 0 === 0
-1 >>> 0 === 4294967295
-2 >>> 0 === 4294967294
-3 >>> 0 === 4294967293
It should be noted (thanks Andy!) that bit shifting in JavaScript converts the arguments to signed 32-bit integers before doing the shifting. Therefore >>> 0
essentially does a Math.floor
on positive numbers:
1.1 >>> 0 === 1
1.9 >>> 0 === 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With