Last active
May 18, 2023 17:47
-
-
Save extremeheat/169db4f3eb88dc7cdc4448560526e9e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var addBinary = function(a, b) { | |
let binaryStringA = a.split('').reverse() | |
let binaryStringB = b.split('').reverse() | |
let valA = 0n | |
for (let i = 0n; i < binaryStringA.length; i++) { | |
if (binaryStringA[i] == 1) valA += 2n ** i | |
} | |
let valB = 0n | |
for (let i = 0n; i < binaryStringB.length; i++) { | |
if (binaryStringB[i] == 1) valB += 2n ** i | |
} | |
return (valA + valB).toString(2) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment