How to code for Binary to Decimal conversion using javascript?
Snippet Code
Rate this page :
[ 0 votes]
The sample code which allows to convert numerical binary values into decimal values. The simple javascript code to convert binary format into decimal is given below.
<script type='text/javascript'>
var num1;
var num2;
function bin_to_dec()
{
num1 = document.binaryform.text1.value;
if (isNaN(num1)) {
alert("Accept only numbers");
}
else{
num2 = parseInt(num1, 2);
document.binaryform.text2.value = num2;
}
}
</script>
<form name="binaryform">
<b>Input :</b>
<input type="text" name="text1">
<b>Output : </b>
<input type="text" name="text2" readonly>
<input type="button" name="butt1" value="Convert" onclick="bin_to_dec()">
</form>