Nodes/ComfyUI-Pt-Wrapper/Pt Bitwise Xor
ComfyUI Node

Pt Bitwise Xor

Toggling bits and checking parity without Python

By HowToSD·Created about a year ago·Updated about a year ago· 7
Pt Bitwise Xor
  • tens_a
  • tens_b
  • TENSOR

XOR is the bitwise operator people remember least and underuse the most. It's 1 only where the two inputs differ, which gives it two genuinely useful personalities: it toggles a flag (xor with a mask flips exactly the bits you name), and it computes parity (how many bits differ between two values). Pt Bitwise Xor wraps torch.bitwise_xor(tens_a, tens_b) and hands both of those to you as a node.

Toggling is the practical one. In a data preprocessing graph, XOR with a fixed mask is the standard way to flip a set of bits without touching anything else - the same job OR does when you want to set them. It's also a classic cheap trick for "detect changes between two tensors": wherever the inputs match, XOR gives zero.

Inputs

  • tens_a - first TENSOR, integer dtype.
  • tens_b - second TENSOR, same shape.

Output: a same-shape TENSOR with a ^ b element-wise.

Same family, same rules

There are six bitwise nodes in this pack (And, Or, Not, both shifts, and this one) and they're all thin, correct wrappers over PyTorch. That's the pack's design philosophy in miniature: no magic, just visual access to torch ops. The bitwise family is the most specialized of the bunch - the pack's headline workflows (ResNet on CIFAR-10, the dog/cat classifier, the from-scratch Transformer) don't use them, and neither will you unless you're doing hand-rolled feature encoding.

The one rule that bites people: integer (or bool) tensors only. A float input raises a runtime error with no graceful message, so cast with PtToInt32 if your data came from anywhere near an image pipeline. Keep tens_a and tens_b shape-aligned too. And if what you actually want is "True where the boolean tensors disagree," PtLogicalXor is the clearer-named sibling - but functionally this node handles bool tensors identically.

Installing it

Part of ComfyUI-Pt-Wrapper (Hide Inada / HowToSD). Get it from ComfyUI Manager by searching the pack title, or:

cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper

Restart ComfyUI. The pack installs a heavy requirements.txt (scikit-learn, transformers, datasets, gensim, scipy, pandas, peft, accelerate...). If Manager's install fails, pip install -r requirements.txt inside the clone. No model files involved for the tensor nodes.

CategoryData Analysis

Inputs (2)

NameTypeDefaultDescription
tens_aTENSOR
tens_bTENSOR

Outputs (1)

NameTypeDescription
TENSORTENSOR