LogicUtil_Bitwise Xor
The 'toggle' gate — LogicUtil_Bitwise Xor, and why it's the odd one out
- INT
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 ^ 10→1100 ^ 1010→0110→65 ^ 3→101 ^ 011→110→6255 ^ 255→0(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 0input2(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 | 5is7, but3 ^ 5is6. 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.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| input1 | INT | 0 | — |
| input2 | INT | 0 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| INT | INT | — |