Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

javascript

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

like image 938
var x Avatar asked Sep 17 '10 10:09

var x


1 Answers

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
like image 142
Skilldrick Avatar answered Oct 09 '22 03:10

Skilldrick