How can a UINT32 value represeting a float value been decoded as float?
- Armin Beck
How can a UINT32 value represeting a float value been decoded as float in javascript?
Supposing you are using an existing display from the templates such as "ATVISE/Default/Number/in_out_value", then you can extend it with a function
from http://stackoverflow.com/questions/4414077/read-write-bytes-of-float-in-js named "Bytes2Float32()" to convert the UINT32 integer value to a float value.
function Bytes2Float32(bytes) {
var sign = (bytes & 0x80000000) ? -1 : 1;
var exponent = ((bytes >> 23) & 0xFF) - 127;
var significand = (bytes & ~(-1 << 23));
if (exponent == 128)
return sign * ((significand) ? Number.NaN : Number.POSITIVE_INFINITY);
if (exponent == -127) {
if (significand == 0) return sign * 0.0;
exponent = -126;
significand /= (1 << 22);
} else significand = (significand | (1 << 23)) / (1 << 23);
return sign * significand * Math.pow(2, exponent);
}
Example: Feed the function with the value 0x42c83852 for example and it returns the value 100.11