Skip to content

Instantly share code, notes, and snippets.

@extremeheat
Last active May 18, 2023 17:47
Show Gist options
  • Save extremeheat/169db4f3eb88dc7cdc4448560526e9e9 to your computer and use it in GitHub Desktop.
Save extremeheat/169db4f3eb88dc7cdc4448560526e9e9 to your computer and use it in GitHub Desktop.
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