Instructions
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.
Examples:
(Input1, Input2 --> Output (explanation)))
1, 1 --> "10" (1 + 1 = 2 in decimal or 10 in binary)
5, 9 --> "1110" (5 + 9 = 14 in decimal or 1110 in binary)
My solution:
function addBinary(a,b){
return (a+b).toString(2)
}
Explanation
First I just summed the numbers and after that I just converted it to string with a 2 parameter so it would only be 0 and 1 (binary code)
Did you like this solution? 👇🤔
Top comments (2)
Very good and simple solution
Thanks for your comment bro!!