アルゴリズム73-バイナリAddition//進数
3150 ワード
Q.
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)
A) function addBinary(a,b) {
return (a + b).toString(2)
}
少し前にヒューパから教わった振子を変える方法を思い出しました…!私はこの日だけを待っています!使うタイミング…!!!😆parseInt(a, b) // 표시된 수(a)를 진법(b)에 맞춰 10진법으로 변환한다.
parseInt(100, 2) // 4
parseInt('a', 16) // 10
(a).toString(b) //표시된 10진법 수(a)를 진법(b)에 맞춰 변환한다.
(4).toString(2) // '100'
(10).toString(16) // 'a'
Reference
この問題について(アルゴリズム73-バイナリAddition//進数), 我々は、より多くの情報をここで見つけました
https://velog.io/@pearpearb/알고리즘-73-Binary-Addition-진법
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
function addBinary(a,b) {
return (a + b).toString(2)
}
少し前にヒューパから教わった振子を変える方法を思い出しました…!私はこの日だけを待っています!使うタイミング…!!!😆parseInt(a, b) // 표시된 수(a)를 진법(b)에 맞춰 10진법으로 변환한다.
parseInt(100, 2) // 4
parseInt('a', 16) // 10
(a).toString(b) //표시된 10진법 수(a)를 진법(b)에 맞춰 변환한다.
(4).toString(2) // '100'
(10).toString(16) // 'a'
Reference
この問題について(アルゴリズム73-バイナリAddition//進数), 我々は、より多くの情報をここで見つけました https://velog.io/@pearpearb/알고리즘-73-Binary-Addition-진법テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol