Skip to content

Binary-to-Decimal number converter implemented with JavasScript

License

Notifications You must be signed in to change notification settings

AleNoia/bin2dec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

Repository files navigation

👨‍💻 Bin2dec

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.

GitHub language count Repository size License GitHub last commit

image


📌 Table of Contents


💡 Features

  • ⇆ Convert a binary number to decimal
  • 📋 Copy the result

🎯 Purpose

My purpose with this project is how to do a binary number converter.

During this project I learned too:

  • more about Javascript
  • make a different UI
  • how to copy a value from an element

🛠 Installation

You need to download git initially

Run this command to clone the repository:


git clone https://github.com/AleNoia/bin2dec.git

🎲 Runnig

Start the index.html file in the src folder


📝 Utilization

It is a very simple to use Bin2Dec

1. Insert the binary number into the first input

2. Click the convert button

// ======================================== [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
}

3. The result will come out in the second input

4. You can copy the result

image

// ======================================== [COPY]
this.copyResult = () => {
    let copyValue = this.resSelector;
    copyValue.select();
    document.execCommand('copy');
}

⚙ Technologies used

Technologies that were used in the construction of the project:


🤝 Contributing

  1. Fork the project.
  2. Create a new branch with your changes: git checkout -b my-feature
  3. Save your changes and create a commit message telling you what you did: git commit -m" feature: My new feature "
  4. Submit your changes: git push origin my-feature

If you have any questions check this guide on how to contribute

Feel free to contribute 🙂


👋 Author

If you want to contact, mail me or send a message on Twitter

Gmail Badge badge


🧾 License

Released in 2021. This project is under the MIT license.

Made by Igor Noia 👋

Releases

No releases published

Packages

No packages published