2

I came across a Solution for Binary Addition and I'm having a hard time understanding how it worked. Mainly I need to know what '>>>' does? Here is the solution:

function addBinary(a,b) {
  let sum = a + b;
  return (sum >>> 0).toString(2);
}

addBinary(1,2) // 11
Eric
  • 6,563
  • 5
  • 42
  • 66
j3kkuh
  • 21
  • 3
  • It's a binary [unsigned right shift](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Right_shift) – Andrei Nemes Dec 18 '17 at 01:55
  • 1
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Unsigned_right_shift – Andrew Li Dec 18 '17 at 01:55
  • 2
    `>>>` is a right shift. `>>> 0` doesn't actually shift anything, it just convert `sum` into an integer as `a` and `b` could be floating point numbers. Try it: `console.log(Math.PI >>> 0);`. – ibrahim mahrir Dec 18 '17 at 01:58

0 Answers0