To answer the original question that was closed due to an invalid moderation. Binary Floating point to decimal JavaScript fucntion
This function below basically does the math based on the floating point logic.
Does anyone know of a built in function in JavaScript to do this? or a more straight forward way?
function fp32BinToDec(inputFpBinDiv) {
var inputFpBin = document.getElementById(inputFpBinDiv).value;
var expBin = inputFpBin.substring(1, 9);
var mantBin = inputFpBin.substring(9, 33);
var expDec = (parseInt(expBin, 2) - 127);
var mantDec = (parseInt(mantBin, 2) / (2 ** 23));
var dec = ((1 + mantDec) * (2 ** (expDec)));
document.getElementById('output').innerHTML = dec;
console.log(dec);
return dec;
}
<!DOCTYPE html>
<html>
<head>
<title>Floating point Binary to Decimal</title>
<script src="site.js"></script>
</head>
<body>
<button onclick="fp32BinToDec('inputField')">Convert to Decimal</button><br>
<input id="inputField" value="01000100100110011010000000000000"></input><br>
<p>Output: </p>
<div id="output"></div><br>
<p>Default Floating point binary should result a decimal of 1129</p>
</body>
</html>