Nodes/ComfyUI-JDCN/LogicUtil_Bitwise Xor
ComfyUI Node

LogicUtil_Bitwise Xor

The 'toggle' gate — LogicUtil_Bitwise Xor, and why it's the odd one out

By daxcay·Created 2 years ago·Updated about a year ago· 159
LogicUtil_Bitwise Xor
    • INT
    input10
    input20

    The one-line version

    LogicUtil_Bitwise Xor returns an integer whose bits are 1 where the two inputs differ - one has a 1 and the other has a 0. XOR ("exclusive or") is the toggle operator: XOR the same value twice and you get back what you started with. In a diffusion graph that makes it great for flipping seeds or flags without tracking any state.

    It's part of the LogicUtil family inside ComfyUI-JDCN, the pack people mostly know for its folder/file nodes (the JDCN_* tools that get recommended on r/comfyui for directory-based loading). LogicUtil is the pack's logic toolbox, credited in the source to aria1th's ComfyUI-LogicUtils.

    How it works

    Bit by bit: output bit is 1 only when the inputs disagree.

    • 12 ^ 101100 ^ 101001106
    • 5 ^ 3101 ^ 0111106
    • 255 ^ 2550 (every bit agrees)

    That last property - x ^ x == 0 and x ^ y ^ y == x - is the party trick. You can flip a value and flip it back with no memory node required.

    The source is input1 ^ input2, Python's XOR operator. Nothing else to it.

    Inputs and outputs

    • input1 (INT) - first integer, default 0
    • input2 (INT) - second integer, default 0
    • Output: INT - the bitwise XOR

    Two integer inputs, one integer output. Standard.

    Installing it

    Same install as the whole pack:

    Easiest - ComfyUI Manager → Install Custom Node → search ComfyUI-JDCN → install → restart.

    Manual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/daxcay/ComfyUI-JDCN.git
    cd ComfyUI-JDCN
    pip install -r requirements.txt
    

    Restart ComfyUI. The only dependency in the pack is piexif; no models, no API keys.

    Common issues

    • INT only. Floats throw a TypeError. Integer sources.
    • XOR is not OR. Or sets a bit if either input has it; Xor sets it only if exactly one does. 3 | 5 is 7, but 3 ^ 5 is 6. If your mask math suddenly looks off by one, check whether you grabbed Xor when you meant Or.
    • It's the least "intuitive" of the bitwise gates. If a workflow shows XOR and you don't know why it's there, the author is probably using the toggle trick above - leave it alone unless you're modifying that logic deliberately.

    When you'd actually reach for it

    Toggle flags deterministically: seed ^ 0x1234 gives you a "second variant" seed you can flip back and forth between, which is handy for A/B comparisons in a loop. It's also the classic hash/checksum primitive. Niche, but when you need a reversible flip, nothing else in this family does it in one node.

    CategoryLogicUtil

    Inputs (2)

    NameTypeDefaultDescription
    input1INT0
    input2INT0

    Outputs (1)

    NameTypeDescription
    INTINT