Nodes/ComfyUI-Minitools/RGB or HEX Convert to DEC 👻
ComfyUI Node

RGB or HEX Convert to DEC 👻

Every Color, Squeezed Into One Number

By lepiai·Created 2 years ago·Updated 3 days ago· 9
RGB or HEX Convert to DEC 👻
    • decimal_value
    colorhex

    When a color needs to be a single integer

    Some nodes and scripts want a color as one number rather than three channels. RGB or HEX Convert to DEC takes either a hex string like #ff0000 or an RGB tuple like (255, 0, 0) and hands you back the single decimal equivalent - 16711680 for pure red, in both cases. If that number looks familiar, it's because it's the same value you'd get treating the hex as a base-16 integer: 0xff0000.

    Reach for it when you're feeding a color into something that accepts one numeric value, or when you're storing a palette as plain integers and need to round-trip it through the graph. It's the natural sibling to this pack's Color to RGB node - one splits a color into channels, this one collapses a color into a single value.

    How it works

    The logic is short and worth understanding because it has two paths:

    • If the input arrives as a tuple - (255, 2, 1) - it computes R * 256² + G * 256 + B. That's standard RGB-to-integer packing.
    • Otherwise it treats the input as a hex string, strips a leading # if present, and runs int(hex, 16).

    Same result either way, which is a nice bit of redundancy. The subtle thing: the input is declared as a STRING with forceInput, yet the code checks for tuples. That tuple branch only ever fires when you wire in a wildcard (*) output from a node like LayerStyle's picker that actually emits a tuple despite the declared type. If you're feeding it plain text, you're on the string path.

    The interface

    • colorhex (STRING, forceInput) - a hex color (with or without #) or a color tuple from another node.
    • Output: decimal_value (wildcard type) - the color as a single integer.

    That's the whole node. No settings, no mode switch - it decides for itself based on what you hand it.

    Installing it

    Part of the ComfyUI-Minitools pack from lepi ai - seven small utility nodes under the "MiniTools" category, ghost 👻 in the display names. Nothing to download, no API keys; this is pure number crunching.

    cd ComfyUI/custom_nodes
    git clone https://github.com/lepiai/ComfyUI-Minitools
    

    then restart ComfyUI, or use ComfyUI Manager → search "ComfyUI-Minitools" → Install → Restart.

    One pack-level gotcha that applies even to this offline node: the pack imports its LLM node at startup, and that module needs the openai package. If openai isn't installed, the whole pack fails to load and every node in it disappears, this one included. Manager installs the pinned requirements for you; if you cloned manually, run pip install -r requirements.txt first. One more expectation-setting note: it ignores alpha entirely - RGB only. If you need a color with transparency packed into an int, this isn't the node.

    CategoryMiniTools

    Inputs (1)

    NameTypeDefaultDescription
    colorhexSTRING

    Outputs (1)

    NameTypeDescription
    decimal_value*