Algorithm 6 - [JS] Binary Addition

luneah·2021년 12월 4일
0

Algorithm CodeKata

목록 보기
6/13
post-thumbnail

Binary Addition

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)

📌 Needs ) Input1과 Input2를 더한 결과를 2진법으로 나타내라.

📁 Sol ) a와 b를 합친 결과를 2진수로 반환

function addBinary(a,b) {
  return (a + b).toString(2);
}
profile
하늘이의 개발 일기

0개의 댓글