ComfyUI Node

from hex

Read a hex float back to a number — the exact opposite of rounding

By StableLlama·Created about a year ago·Updated a day ago· 48
from hex
    • FLOAT
    hex_value0x0.0p+0

    from hex (Basic data handling: FloatFromHex) is the read-back half of the pack's lossless float round-trip. It takes a hexadecimal float string and returns the exact float it represents, using Python's float.fromhex(). One required input, hex_value (a STRING, defaulting to 0x0.0p+0), one FLOAT output.

    Pair it with the pack's to hex (FloatHex) node and you've got something most text formats can't offer: a number stored as text that comes back bit-for-bit identical. FloatHex turns 3.0 into 0x1.8p+1; FloatFromHex turns 0x1.8p+1 back into exactly 3.0. No rounding at a few decimal places, no 0.30000000000000004 drift creeping in through a decimal text representation.

    The format, demystified

    If you've only ever seen hex as FF or A3, these strings look weird - 0x1.999999999999ap-4. That's a base-2 version of scientific notation: 0x says hex, the fraction is the significand, and p-4 is the base-2 exponent (like an e in decimal scientific notation). 0x1.8p+1 means 1.5 × 2¹ = 3.0. The default 0x0.0p+0 is just zero. You rarely need to read these by hand - the point is they round-trip exactly - but understanding the shape makes the node feel a lot less magical.

    When you'd actually use it

    Two solid use cases. First, persistence: save a computed float as hex text (the pack's save-STRING node writes it to a file), then load that file on a later run and feed it into FloatFromHex to get the exact same number back. If exactness matters - a seed, a ratio, a calibration value - this beats writing "3.5" as decimal text, which has to parse back through rounding.

    Second, exchanging floats with other tools that speak hex floats - some config formats, serialization libraries, and low-level debug output use exactly this representation. If something hands you 0x1.8p+1, this is the node that turns it into a number you can compute with.

    Installing it

    Part of the Basic data handling pack by StableLlama. ComfyUI Manager → search "Basic data handling" → install → restart. Manual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
    

    then restart. No dependencies, no requirements.txt, no model downloads.

    Troubleshooting

    float.fromhex() is strict - give it a malformed string (like a plain "3.5" or "0xZZ") and it throws, turning the node red. The strings this node accepts are exactly the ones FloatHex produces, so if you're constructing them yourself, generate them with the sibling node rather than by hand. And note the input is a STRING: this is not the node for "a number that happens to be written in hex digits" - that's a base-conversion job, different thing entirely.

    CategoryBasic/FLOAT

    Inputs (1)

    NameTypeDefaultDescription
    hex_valueSTRING0x0.0p+0

    Outputs (1)

    NameTypeDescription
    FLOATFLOAT