forxtu
8/6/2019 - 9:50 PM

Add binary

Implement a function that adds two numbers together and returns their sum in binary. The conversion can be done before, or after the addition.

The binary number returned should be a string.

JS Bin

// source https://jsbin.com/qosopig

const addBinary = (a, b) => (a + b).toString(2);

console.log(addBinary(1, 5))

const convertToBinary = (number) => {
  return number.toString(2);
}

console.log(convertToBinary(6))