Convert IEEE 754 double precision numbers into C99-style hex floats.
Hexadecimal floats are the base 16 version of a regular floating point number. They are useful when debugging routines which manipulate floating point numbers since it is easier to inspect their contents than it is with decimal floats (which are often rounded when displayed to make things look nicer). Hex floats may not be as pretty as decimal floats to an average user, but they present the information stored in a float value more honestly.
Here is an example of a hexadecimal float string:
Breaking it down, the parts of the float are as follows:
0x 10a . fbc p -20\__/ \___/ | \___/ | \___/| | | | | |+-Prefix +-Decimal +-Delimiter| | |+-Whole number +-Exponent|+-Fraction
The whole number and fractional part of the float is interpreted as a fixed point decimal fraction,
0x10a.fbc = 0x10afbc * 16⁻³ = 266.9833984375
While the exponent is a power of two which is multiplied by the number,
p-20 = 2⁻²⁰
Putting it all together,
0x10a.fbcp-20 = 0x10afbc * 16⁻³ * 2⁻²⁰ = 0.0002546152099967003
var doubleToHex =var numbers = 1 -1 0 05 01 1e20 Mathnumbers
dec: 1 hex: 0x1p0dec: -1 hex: -0x1p0dec: 0 hex: 0x0p0dec: 0.5 hex: 0x0.8p0dec: 0.1 hex: 0x0.1999999999999ap0dec: 100000000000000000000 hex: 0x56bc75e2d6310000p0dec: 5.562684646268003e-309 hex: 0x1p-1024
npm i double-hex
num into a hexadecimal string
numis a Number
Returns A C99 style hex string encoding number.
(c) 2015 Mikola Lysenko. MIT License