Dark Mode
Enable Console
addBinary(a,b)
/*
Adds two numbers together and returns their sum in binary.
*/
addBinary(10,15);
// 11001
addBinary(127, 564);
// 1010110011
Solution by - Need4Swede
function addBinary(a,b) {
if(a+b >= 0) {
return (a+b).toString(2);
}
else {
return (~a+b).toString(2);
}
}
Try it yourself - Codewars Source