How to Create Converter for Binary to Decimal
Submitted by alpha_luna on Monday, August 22, 2016 - 17:24.
If you are looking for a simple Converter For Binary To Decimal then you are at the right place. This converter works by entering a desired numeric value from the user then the user clicks the "Ok" button to convert the Binary Value to in Decimal Form.
This program creates using JavaScript.
You can also check the live demo of this simple tutorial, so you can get an idea and you can try this out, let's start coding.
JavaScript Source Code
This script will ask the user to input the numerical value to convert binary to decimal.
Output:
Where the user types the value of binary to convert into decimal.
This is the output after the user types the numerical value.
For the full source code, kindly click the "Download Code" button below.
If you are interested in programming, we have an example of programs that may help you even just in small ways.
So what can you say about this work? Share your thoughts in the comment section below or email me at [email protected]. Practice Coding. Thank you very much.
- <script>
- function binaryConvert_toDecimal( binary_Value ) {
- var decimalNumber = 0;
- var placeValue = 1;
- while ( binary_Value > 0 ) {
- var remainder = binary_Value % 10;
- var digitValue = remainder * placeValue;
- decimalNumber = decimalNumber + digitValue;
- placeValue *= 2;
- binary_Value = Math.floor( binary_Value / 10 );
- }
- return decimalNumber;
- }
- var input = parseInt(prompt("Enter your desired value."));
- input_solve = binaryConvert_toDecimal(input);
- if (!isNaN(input)) {
- document.write("<h2><b style='color:red;'>" +input + "<sub>2</sub></b> in binary is equivalent to <b style='color:blue;'>"
- + input_solve + "<sub>10</sub></b> in decimal. </h2>" );
- }
- while(isNaN(input)){
- input = parseInt(prompt("Please enter a numerical value."));
- input_solve =binaryConvert_toDecimal(input);
- if (!isNaN(input)) {
- document.write("<h2><b style='color:red;'>" +input + "<sub>2</sub></b> in binary is equivalent to <b style='color:red;'>"
- + input_solve + "<sub>10</sub></b> in decimal.</h2>" );
- }
- }
- </script>
Add new comment
- 9 views