Binary-to-Decimal number converter implemented with JavasScript
Bin2Dec allows the user to enter binary digits, 0’s and 1’s, and then displays its decimal equivalent, in any sequence and then displays its decimal equivalent.
My purpose with this project is how to do a binary number converter.
During this project I learned too:
You need to download git initially
Run this command to clone the repository:
git clone https://github.com/AleNoia/bin2dec.git
Start the index.html
file in the src
folder
It is a very simple to use Bin2Dec
// ======================================== [CONVERT FUNCTION]
this.convert = () => {
dec = 0
let bin = this.binSeletor.value
let test = /^[01]+$/g.test(bin);
// Conditional to accept only 0 and 1
if (!test) {
this.resSelector.value = "Enter only 1 or 0";
return;
}
try {
for (var i = 0; i < bin.length; i++) {
// CONVERT
dec = dec + parseInt(bin[i]) * Math.pow(2, bin.length - 1 - i);
}
} catch {
this.resSelector.value = "Error"
}
// PUTTING RESULTS IN THE DIV
this.resSelector.value = dec
}
// ======================================== [COPY]
this.copyResult = () => {
let copyValue = this.resSelector;
copyValue.select();
document.execCommand('copy');
}
Technologies that were used in the construction of the project:
git checkout -b my-feature
git commit -m" feature: My new feature "
git push origin my-feature
If you have any questions check this guide on how to contribute
Feel free to contribute 🙂
If you want to contact, mail me or send a message on Twitter
Released in 2021. This project is under the MIT license.
Made by Igor Noia 👋