What does ' >>> ' mean in javascript? [duplicate]

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

Answers:

Answer

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
Answer

It's a bitwise operator. It means shift n by 0 bits. Not sure what it's trying to do in the instance you show.

a >>> b  // shift a by b bits to the right, padding with zeros

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.