Skip to content

Commit 554bcd4

Browse files
Merge pull request #8 from AnwarHossainSR/dev1.0
Dev1.0
2 parents 153145a + 3bc46ea commit 554bcd4

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{
2-
"cSpell.words": ["MCMXCIV", "Palindrom", "strs"]
2+
"editor.fontSize": 16,
3+
"editor.fontLigatures": false,
4+
"editor.fontWeight": "normal"
35
}

67-addBinary.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const addBinary = (a, b) => {
2+
let sum = '',
3+
carry = 0;
4+
5+
a = a.split('');
6+
b = b.split('');
7+
const len = Math.max(a.length, b.length);
8+
for (let i = 0; i < len; i++) {
9+
const x = parseInt(a.pop() || 0);
10+
const y = parseInt(b.pop() || 0);
11+
const temp = x + y + carry;
12+
sum = (temp % 2) + sum;
13+
carry = Math.floor(temp / 2);
14+
}
15+
if (carry) sum = carry + sum;
16+
17+
return sum;
18+
};
19+
20+
console.log(addBinary('1010', '1011'));

0 commit comments

Comments
 (0)