1
Signed right shift        5 >> 1   0101 >> 1    0010     2

>>> Zero fill right shift 5 >>> 1 0101 >>> 1 0010 2
These examples appear to be same!I want to know difference between these two.

1 Answers1

1

With >>>, 0s are shifted in from the left.

With >>, copies of the leftmost bit are shifted in from the left. If the leftmost bit is a 0, it'll be the same as >>>, but if the leftmost bit is a 1, it will be different. For example:

// in binary, -5 is represented as 111111111111... on the left
console.log(-5 >> 4);  // -5 >> 4 results in the left side still looking like 111111...
console.log(-5 >>> 4); // -5 >>> 4 shifts in 5 zeros: 000001111111...

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators

CertainPerformance
  • 260,466
  • 31
  • 181
  • 209