npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

fhex

v1.0.0

Published

Hex float conversion: toHex for formatting, fromHex for parsing. IEEE 754 hexadecimal format (0x1.8p+1).

Readme

fhex

NPM

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().

Requirements

Node.js >= 20

Usage

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

Bit-level inspection

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.

Format

Floating point numbers are represented as ±0xh.hhhp±d, where:

  • ± is the sign (- for negative, omitted for positive)
  • 0x is the hex prefix
  • h.hhh is the significand in hexadecimal
  • p±d is the exponent in decimal (base 2)

Special values:

  • ±0x0p+0 for zero
  • ±inf for infinity
  • nan for quiet NaN
  • nan:0x... for NaN with payload

Parsing features

  • Underscores for readability: 0x1_000p+0
  • NaN payloads preserved: nan:0x123
  • Case-insensitive: INF, NaN, 0X1P+0
  • Whitespace trimmed
  • Optional exponent: 0x1.8 is equivalent to 0x1.8p+0

License

Apache-2.0