Nodes/ComfyUI-JDCN/LogicUtil_Bitwise Shift
ComfyUI Node

LogicUtil_Bitwise Shift

Fast multiply-by-two (and divide-by-two) — LogicUtil_Bitwise Shift

By daxcay·Created 2 years ago·Updated about a year ago· 160
LogicUtil_Bitwise Shift
    • INT
    input10
    input20

    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 (11110) gives 6. Shift right by a positive amount divides: 7 >> 1 (11111) 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 << 232, and 8 << -14. One node, both directions.

    Inputs and outputs

    • input1 (INT) - the number to shift, default 0
    • input2 (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, Multiply by 2 is 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 >> 1 is -4, not -3. If exact integer division matters, use a Divide node.

    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.

    CategoryLogicUtil

    Inputs (2)

    NameTypeDefaultDescription
    input1INT0
    input2INT0

    Outputs (1)

    NameTypeDescription
    INTINT