LogicUtil_Bitwise Shift
Fast multiply-by-two (and divide-by-two) — LogicUtil_Bitwise Shift
- INT
The one-line version
LogicUtil_Bitwise Shift slides the bits of one integer left or right. A left shift by n is multiply by 2^n; a right shift is integer divide by 2^n. In a diffusion graph this is usually overkill - Multiply does the same job more readably - but it's the honest fast path for power-of-two math, and it's how a lot of resolution/step math works under the hood.
It's part of the LogicUtil family inside ComfyUI-JDCN, the pack best known for its file and directory tools. The LogicUtil section is credited to aria1th's ComfyUI-LogicUtils in the pack's source.
How it works
Shifting left moves every bit up a position, dropping the top bit and padding the bottom with zeroes. 3 << 1 (11 → 110) gives 6. Shift right by a positive amount divides: 7 >> 1 (111 → 11) gives 3 (the fractional remainder just falls off).
This node's twist: it lets you encode the direction in the sign of input2. Positive input2 shifts left, negative input2 shifts right - because Python's << with a negative count actually does a right shift. The implementation:
if abs(input2) > 32:
raise ValueError("input2 must be between -32 and 32")
return (input1 << input2,)
So 8 << 2 → 32, and 8 << -1 → 4. One node, both directions.
Inputs and outputs
input1(INT) - the number to shift, default 0input2(INT) - how many bits to shift; positive = left, negative = right, must stay within ±32- Output: INT - the shifted result
Installing it
Same as the rest of the 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. Only dependency is piexif; no models to fetch.
Common issues
- "input2 must be between -32 and 32" - that's a deliberate guard in the source. Shifting by more than 32 bits on a 64-bit int is either nonsense or an infinite-precision trip in Python, so the node refuses. Drop your shift amount.
- You may genuinely mean Multiply.
x << 1=x * 2;x << 2=x * 4. For anyone reading the graph later,Multiplyby2is clearer. Reach for shift when you're doing many power-of-two steps, or when you found this node in someone else's workflow. - Right shift floors toward negative infinity, not toward zero (Python semantics).
-7 >> 1is-4, not-3. If exact integer division matters, use aDividenode.
When you'd actually reach for it
Power-of-two resolution math - halving or doubling dimensions, seed ranges, mask sizes - where the operands are always nice round binary numbers. It's a specialist tool. Know that it exists, reach for Multiply first, and keep this one for when the graph gets clever.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| input1 | INT | 0 | — |
| input2 | INT | 0 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| INT | INT | — |