Pt Bitwise And
Doing flag math inside ComfyUI
- tens_a
- tens_b
- TENSOR
Let's be honest about what this node is: a one-line PyTorch call - torch.bitwise_and(a, b) - dressed up as a ComfyUI node. If you've ever done data work with bit flags, it's exactly what you expect. If you haven't, you can skip it and not miss anything. This is a node for the niche the whole pack serves: doing real PyTorch data work in the node graph instead of a Jupyter notebook.
Pt Bitwise And takes two integer tensors and ANDs their bits element by element. In practical terms that's how you test "is this flag bit set" - if flags & MASK comes out nonzero, the bit is on. The pack's example workflows are mostly image classifiers and transformers, so bitwise ops aren't in the spotlight, but they show up whenever someone builds a preprocessing graph that packs categorical flags into integers.
The inputs that matter
tens_aandtens_b- bothTENSOR, both integer dtype, same shape. Broadcast semantics apply, but keep them aligned and life is simpler.
The single output is a TENSOR of the same shape with the element-wise result. Wire it into any other Pt* node - comparisons, PtToInt32, whatever your graph needs next.
The one real gotcha
Floating point tensors will throw. torch.bitwise_and is integer-only (and bool) in PyTorch, and this node doesn't guard you with a friendly message. If you're feeding it data straight out of an image pipeline, you'll get a runtime error - run your tensor through PtToInt8/PtToInt32 first, or build your integers with PtIntCreate. If you just want a True/False mask rather than actual bits, the pack's PtLogicalAnd is the node you actually want; bitwise is for when you're treating an int as a set of flags.
Installing it
This ships in ComfyUI-Pt-Wrapper, the no-code PyTorch pack by Hide Inada (HowToSD, same author as ComfyUI-Data-Analysis). Install it in ComfyUI Manager by searching "ComfyUI-Pt-Wrapper", or:
cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper
Then restart ComfyUI. Heads up: the pack is a heavyweight - requirements.txt pulls pandas, scipy, scikit-learn, transformers, datasets, gensim and friends. If Manager's install fails, run pip install -r requirements.txt inside the cloned folder yourself. None of the tensor nodes need model downloads; only the example dataset workflows (CIFAR-10, Fashion-MNIST) fetch data, and those auto-download.
Expect this node to mostly sit quietly in the corner of a larger graph. It doesn't do much, but when you're hand-rolling a feature-encoding step, it's the right tool and it behaves exactly like PyTorch says it will.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| tens_a | TENSOR | — | |
| tens_b | TENSOR | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| TENSOR | TENSOR | — |