(The below obsoleted by the clarification by the OP.)
parseInt
(MDN | spec) is perfectly happy to parse hex in that format for you:
var hexValue = parseInt("0x43480000");
console.log(hexValue);
It will see the 0x
at the beginning and assume hex. If you had a string in hex without the prefix ("43480000"
), you'd use parseInt(str, 16)
to tell parseInt
to use base 16 (hex). But since you have the prefix, there's no need.
The result will be a JavaScript number, which by definition is a "double" (IEEE-754 double-precision binary floating point).
You've said you want 0x43480000
to come out as 200.0. That means you're not really parsing hex, you're trying to take a string containing the bit pattern of an IEEE-754 floating-point number, expressed as hex, and get the equivalent IEEE-754 floating-point number. That's very different from "parsing hex."
The calculator you referred to works with IEEE-754 single-precision binary floating point values. The 0x43480000 bit pattern isn't 200 in double-precision binary floating point. But 0x40690000 is.
The only easy way I know of to do that is with DataView
:
var dv = new DataView(new ArrayBuffer(8));
dv.setUint32(0, parseInt("0x40690000"));
var num = dv.getFloat64(0)
console.log(num);
If you want to convert the single precision version (0x43480000), I don't think there's anything built-in that's going to do it for you. You'll have to isolate the mantissa and exponent bits, do the widening, and then do the above.