Nodes/ComfyUI-Pt-Wrapper/Pt Bitwise Left Shift
ComfyUI Node

Pt Bitwise Left Shift

Multiply by powers of two, one bit at a time

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

A left shift moves every bit in an integer up a position, filling the bottom with zeros. If that sentence made sense to you, you're the target audience. If it didn't, here's the practical version: shifting left by one is the same as multiplying by two, so PtBitwiseLeftShift is a cheap, exact way to do powers-of-two arithmetic on tensors - no floating point rounding involved.

Pt Bitwise Left Shift wraps torch.bitwise_left_shift(tens_a, tens_b): tens_a is the value you're shifting, tens_b is the number of positions to shift each element. Both must be integer tensors of matching shape; the shift amounts don't have to be uniform across the batch, which is the whole point of doing this with tensors instead of a scalar PtIntCreate.

Inputs and output

  • tens_a - the TENSOR whose bits get moved.
  • tens_b - the TENSOR of shift counts (how many places to the left).

One TENSOR out, same shape, with tens_a << tens_b computed element-wise.

Where does this actually come up? Mostly in bit-packing tricks: encoding several small integers into one int so a single comparison or lookup handles them together, then shifting to extract the field you want. The pack's own docs file this under "Bitwise operations" in the PyTorch wrapper reference, and in practice it's a companion to the other five bitwise nodes (PtBitwiseAnd, PtBitwiseOr, PtBitwiseXor, PtBitwiseNot, PtBitwiseRightShift). Nobody reaches for it for image gen; people reach for it when they're building a data preprocessing graph and want to be clever about storage.

Watch out for

Integer-only, same as every bitwise node in this pack. A float tensor errors at runtime. Shift counts that are negative or bigger than the bit width produce undefined-ish results (PyTorch raises or wraps depending on the backend), so keep tens_b sane. And if you find yourself wanting a * 2^n for arbitrary float data, don't - use PtMul instead. Shifts are a precision trick, not a general multiply.

Installing it

Part of ComfyUI-Pt-Wrapper (Hide Inada / HowToSD). Easiest via ComfyUI Manager - search the pack title - or:

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

Restart ComfyUI after. The pack's dependency list is long (pandas, scipy, scikit-learn, transformers, datasets, gensim, peft, accelerate, seaborn, matplotlib). If Manager's pip step chokes, cd into the clone and pip install -r requirements.txt manually. No model files needed for this one - the tensor nodes are pure compute.

CategoryData Analysis

Inputs (2)

NameTypeDefaultDescription
tens_aTENSOR
tens_bTENSOR

Outputs (1)

NameTypeDescription
TENSORTENSOR