ComfyUI Node

Bool → Int

Turning True/False into 1/0 without a second thought

By danipisca07·Created 6 months ago·Updated 6 months ago· 0
Bool → Int
    • INT
    valuefalse

    Booleans are great for making decisions, and useless for doing arithmetic. The moment you want a condition to scale something rather than just switch it, you need the boolean as a number. SL_BoolToInt is the two-line trick that does exactly that: True becomes 1, False becomes 0.

    The mechanism, from the source: 1 if value else 0. No ambiguity, no edge cases, no rounding (there's nothing to round). A true condition hands you a 1, a false one hands you a 0.

    Why would you want that? The killer pattern is arithmetic gating - multiplying something by a 0/1 so a condition can attenuate or zero-out a value inside a math chain, no switch node required. Examples:

    • Multiply a denoise or CFG strength by a condition's 0/1 so it drops to zero when the condition fails.
    • Add a condition's integer to a seed or step count to nudge a value when something is true.
    • Convert a "should I include this" check into a batch-count or loop-bound term.

    It's also the natural bridge when a node that wants an integer (a seed, a counter, a math input) is fed by something that outputs a boolean. ComfyUI won't let a BOOLEAN wire plug into an INT input, so this cast is the fix.

    Inputs and outputs:

    • value (BOOLEAN) - the condition, default False
    • Output: INT - 1 if true, 0 if false

    Installing it

    Ships with ComfyUI-SimpleLogics. Install via Manager (search "SimpleLogics"), or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/danipisca07/ComfyUI-SimpleLogics
    

    Restart, then Add Node → search "Bool → Int" (menu group SimpleLogics/Convert). The pack is dependency-free - no pip step, no models.

    Pair it with

    This node only earns its keep in the company of its siblings. Feed it from SL_CompareInt, SL_CompareFloat, SL_AND, or any boolean source, then send the resulting integer into math. If your downstream wants a float instead, use SL_BoolToNumber (gives 1.0 / 0.0) - same idea, NUMBER output. If you're converting the other direction (an integer flag back into a boolean), that's SL_IntToBool.

    One honest note: it's a tiny node, and if all you need is a one-off toggle, a plain SL_SwitchInt often reads clearer in the graph. Bool → Int shines when the condition participates in math - when the 0/1 is an operand, not just a selection. Use it there and you'll wonder how you lived without it.

    CategorySimpleLogics/Convert

    Inputs (1)

    NameTypeDefaultDescription
    valueBOOLEANfalse

    Outputs (1)

    NameTypeDescription
    INTINT