ComfyUI Node

Binary Expression

Binary Expression

By marco-zanella·Created about a year ago·Updated about a year ago· 0
Binary Expression
    • result
    firsttrue
    secondtrue
    operandand

    The boolean side of marco-zanella's ComfyUI-BooleanExpression pack ships And, Or, Xor, Nand, and Nor as separate nodes. Binary Expression is the Swiss-army version: the same five operations behind a single dropdown. Two booleans in, the operation you pick, one boolean out. If you only want to remember one socket layout for every boolean gate, this is it.

    How it works

    Three required inputs:

    • first - the first boolean value (default true)
    • second - the second boolean value (default true)
    • operand - the operation, chosen from a dropdown: and, or, xor, nand, nor (default and)

    Output is result, a BOOLEAN. The source is a clean switch on the operand - each case maps to the corresponding Python boolean operation (xor is first != second, which is exactly how XOR behaves on booleans). Pick a gate, get its truth table. Nothing else going on.

    The real selling point is the dropdown. Building a compound condition with dedicated nodes means And here, Not there, Or somewhere else - five separate lookups. With Binary Expression, you drag one node and flip the operation from the widget. Change "and" to "nand" without deleting anything. When you're iterating on logic, that's genuinely faster.

    When it beats the dedicated nodes

    Two situations. First, your own private graph, where compactness beats label readability. Second, when the operation is something you'll toggle while debugging - watching a Conditional Branch flip behavior as you cycle the operand dropdown is a nice way to sanity-check logic without rewiring. The flip side: a shared workflow with one node showing "nand" reads worse than a node that literally says "Nand". For hand-offs, the dedicated gates are kinder. For tinkering, this wins.

    Installing it

    Same pack, same trivial install - no models, no Python dependencies (the pack's requirements.txt is empty), pure logic. ComfyUI Manager, search ComfyUI-BooleanExpression, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/marco-zanella/ComfyUI-BooleanExpression.git
    

    Restart ComfyUI, and it's under Boolean Expressions.

    Gotchas

    • Duplicating resets the operand. A copy of the node comes back with the default and, not whatever you had selected. Re-check the dropdown after duplicating - the classic "why did my logic change" culprit.
    • Feed it real booleans. The inputs are BOOLEAN-typed and expect actual booleans from comparison nodes, toggles, or the pack's True/False constants. Don't improvise with unrelated types and hope for truthiness.
    • Both branches downstream still compute. If you chain this into a Conditional Branch, the unselected path upstream still runs - ComfyUI doesn't skip it. Trivial for booleans.

    If you only ever need one gate, the dedicated node is clearer. If you're building logic you'll fiddle with, Binary Expression is the one that keeps the canvas small and the tweaks instant.

    CategoryBoolean Expressions

    Inputs (3)

    NameTypeDefaultDescription
    firstBOOLEANtrueThe first boolean value.
    secondBOOLEANtrueThe second boolean value.
    operandCOMBOandThe boolean operation.

    Outputs (1)

    NameTypeDescription
    resultBOOLEAN