<cfscript>
function hexToFloat(hexStr)
{
// convert to binary. pad with leading zeros
var bin = right(repeatString("0", 32) & FormatBaseN(InputBaseN(hexStr, 16), 2), 32);
var sign = left(bin, 1);
var exp = "";
var man = "";
var offset = "";
if (sign == 1) {
offset = -1;
}
else {
offset = 1;
}
exp = InputBaseN(mid(bin, 2, 8), 2) - 127;
man = BitSHLN(2, 22) + InputBaseN(mid(bin, 10, 23), 2);
dec = man * (2 ^(exp - 23)) * offset;
return dec;
}
</cfscript>
|