ComfyUI Node

xor

The difference detector disguised as a logic gate

By StableLlama·Created about a year ago·Updated a day ago· 48
xor
    • BOOLEAN
    input1false
    input2false

    XOR is the "are these different?" gate, and it's the most underrated node in the boolean family. xor returns true when the two inputs disagree, false when they agree - which is why it's called "exclusive or": it's OR with the both-true case excluded. It's part of Basic data handling, StableLlama's zero-dependency pack, and its real-world superpower is that it's a difference detector disguised as a logic gate.

    Think about how often your workflow needs "these two things don't match": two settings that should be consistent but aren't, two flags that should agree, an "either one but not both" condition. That's exactly XOR. In Python it's input1 != input2 - literally the not-equal comparison of two booleans - and the implementation leans on that, returning true exactly when the inputs differ.

    How it works

    Truth table, which is the whole thing: both false → false; one true → true; both true → false. So it behaves like "did exactly one condition fire?" - a parity check, if you're in a counting mood. Two inputs, one output, no coercion, and it chains with the rest of the pack's logic nodes. The inputs are forceInput, so wire real booleans in rather than hand-toggling.

    The inputs and the output

    • input1 (BOOLEAN, default False)
    • input2 (BOOLEAN, default False)
    • BOOLEAN (output) - true when the inputs differ.

    Nothing else on the node. If you need to detect a mismatch between two values that aren't booleans, feed each through the pack's comparison or casting nodes first and XOR the results.

    Installing it

    Install Basic data handling from ComfyUI Manager (search "Basic data handling"), or:

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

    Restart ComfyUI. No dependencies, no models.

    Troubleshooting

    • "XOR vs OR - I keep grabbing the wrong one." OR is true when both are true; XOR is false when both are true. The "exclusive" in exclusive-or is literally the point. If you want "any of these" use or; if you want "exactly one of these, not both," use xor.
    • "It's true when I expected false." XOR is a difference check - if both inputs are true, it's false. If you expected false and got true, the inputs are disagreeing, which is precisely what you asked the node to detect. Look upstream: one of the two conditions isn't what you think.
    • "I wanted to compare two numbers." Wrong tool - XOR works on booleans. Use the pack's comparison nodes (equal/not-equal) on the numbers themselves, then gate with logic nodes from there.
    CategoryBasic/BOOLEAN

    Inputs (2)

    NameTypeDefaultDescription
    input1BOOLEANfalse
    input2BOOLEANfalse

    Outputs (1)

    NameTypeDescription
    BOOLEANBOOLEAN