Skip to content
This repository was archived by the owner on Aug 26, 2019. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/binarySum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Sum two integers (Bin1 + Bin2) represented as binary numbers and return decimal value

var ConvertBase = function (num) {
return {
from : function (baseFrom) {
return {
to : function (baseTo) {
return parseInt(num, baseFrom).toString(baseTo);
}
};
}
};
};

// binary to decimal
ConvertBase.bin2dec = function (num) {
return ConvertBase(num).from(2).to(10);
};

export const binaryDecimalSum = (Bin1, Bin2) => {
return (ConvertBase.bin2dec(Bin2) + ConvertBase.bin2dec(Bin2));
}