
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
Hex float conversion: toHex for formatting, fromHex for parsing. IEEE 754 hexadecimal format (0x1.8p+1).
Hex float conversion for JavaScript: toHex for formatting, fromHex for parsing.
Uses the IEEE 754 hexadecimal floating-point format (±0xh.hhhp±d) — the same format used by C's %a printf specifier and Java's Double.toHexString().
Node.js >= 20
import { toHex, fromHex } from 'fhex'
// Formatting
toHex(3.0) // '0x1.8p+1'
toHex(-10.0) // '-0x1.4p+3'
toHex(0.5) // '0x1p-1'
// Parsing
fromHex('0x1.8p+1') // 3.0
fromHex('-0x1.4p+3') // -10.0
fromHex('inf') // Infinity
fromHex('nan') // NaN
// Round-trip
const hex = toHex(Math.PI) // '0x1.921fb54442d18p+1'
fromHex(hex) === Math.PI // true
toHexBits and fromHexBits expose the raw 64-bit IEEE 754 encoding as a hex string. This is useful for inspecting NaN payloads and sign bits that are not observable through normal JavaScript operations.
import { toHex, fromHex, toHexBits, fromHexBits } from 'fhex'
toHexBits(1.0) // '3ff0000000000000'
toHexBits(NaN) // '7ff8000000000000'
toHexBits(-0) // '8000000000000000'
// Construct a NaN with a specific payload
const nan = fromHexBits('7ff0000000000123')
toHex(nan) // 'nan:0x123'
// Round-trip NaN payloads through hex float format
const parsed = fromHex('nan:0x123')
toHexBits(parsed) // '7ff0000000000123'
Note: JavaScript engines may canonicalize NaN payloads when values pass through arithmetic operations. The bit-level functions preserve payloads through DataView, but payloads may be lost if the NaN value is used in computations.
Floating point numbers are represented as ±0xh.hhhp±d, where:
± is the sign (- for negative, omitted for positive)0x is the hex prefixh.hhh is the significand in hexadecimalp±d is the exponent in decimal (base 2)Special values:
±0x0p+0 for zero±inf for infinitynan for quiet NaNnan:0x... for NaN with payload0x1_000p+0nan:0x123INF, NaN, 0X1P+00x1.8 is equivalent to 0x1.8p+0Apache-2.0
FAQs
Hex float conversion: toHex for formatting, fromHex for parsing. IEEE 754 hexadecimal format (0x1.8p+1).
We found that fhex demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.