Nodes/ComfyUI ARG Toolkit/Bitwise Right Shift Operator
ComfyUI Node

Bitwise Right Shift Operator

Slide bytes over and see what falls out

By AzelusLightvale·Created 12 months ago·Updated about 10 hours ago· 1
Bitwise Right Shift Operator
    • bitwise_txt
    text_1Hello World!
    text_2Hello World!
    datatypeBinary
    encoding_format
    other_encoding_format

    The Bitwise Right Shift Operator shifts every byte in the first string to the right by the amount encoded in the second string, bit by bit - like pushing the bits off the end of each byte and watching them drop away. It's the reverse of the missing half of the story: where << doubles, >> halves. In an ARG context it shows up in "divide this value" puzzles, in extracting the high-order bits of an encoded stream, and as the recovery step after something was shifted left. It's a utility node, not a headline act, but when you need it there's no better way to do it inside ComfyUI.

    Here's the slightly weird part about how it takes its inputs: the second operand's byte values are the shift amounts. So text_1 is the data you're shifting, and text_2 is a byte (or bytes) whose numeric value tells the node how many positions to shift each corresponding byte. Feed "3" as a string with datatype set to Integer and every byte of text_1 shifts right by three. It's a two-node-in-one design, and it catches people off guard the first time.

    How it works

    Both strings are decoded to bytes according to datatype, then paired up and shifted with x >> y - right-shifting each byte of the first operand by the value of the matching byte in the second. Right shift divides by powers of two: shifting right by 1 cuts a byte's value in half (dropping the least significant bit), shifting by 3 divides by 8. The dropped bits are simply gone - this is not a rotate, and there's no wrap-around. The result is then re-encoded into the same datatype for the output.

    Same rules as the other two-operand bitwise nodes apply:

    1. text_1 and text_2 must decode to equal length - the node raises a ValueError otherwise. Because the shift amounts come from text_2's bytes, each byte of data needs a matching shift byte.
    2. Everything happens on bytes. If you set datatype to String, the node shifts raw UTF-8 bytes and tries to decode the result back to text - which can throw a UnicodeDecodeError when the shifted bytes aren't valid UTF-8. For real bit work, use Hexadecimal, Binary, or Integer.

    The inputs that matter

    • text_1 - the data to shift.
    • text_2 - the shift amounts (as byte values). A short value like "1" or "3" with Integer datatype is the usual move.
    • datatype - how both inputs and the output are interpreted: String, Hexadecimal, Base64, Integer, or Binary.
    • encoding_format - text encoding for String datatype; set Other and fill other_encoding_format for custom codecs.

    Everything comes out of one bitwise_txt output in the same format as the input.

    Installing it

    This node is part of the ComfyUI ARG Toolkit pack. Install the pack via ComfyUI Manager (search "ComfyUI ARG Toolkit") or manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/AzelusLightvale/ComfyUI-ARG-Toolkit
    

    Then restart ComfyUI. The pack installs a real dependency tree - cryptography, secretpy, stegano, invisible-watermark, reedsolo, and transitively torch and opencv-python - so the first run takes a bit. No model downloads, no API keys.

    Gotchas

    The equal-length rule is the usual failure, and the "shift amount comes from the second operand's byte values" design is the one that confuses people - if your result looks like nothing shifted, check what text_2 actually decoded to. And remember right shift is lossy: bits that slide off the end are gone, so there's no inverse unless you kept the originals.

    CategoryARG Toolkit/Utilities/Bitwise

    Inputs (5)

    NameTypeDefaultDescription
    text_1STRINGHello World!The main string to compare against. Accepts format defined in `datatype`
    text_2STRINGHello World!The secondary string to compare against. Accepts format defined in `datatype`
    datatypeCOMBOBinaryThe datatype that the two texts is assumed to be for comparison purpose. Will also output the final output based on the chosen datatype as well.
    encoding_formatCOMBOThe encoding format available for text, may yield different results when converting.
    other_encoding_formatoptSTRINGIf, for some reason, your chosen encoding format is not available in the dropdown, select "Other" in encoding_format and type in your encoding format here. Supports all format written in Python's `encoding` module.

    Outputs (1)

    NameTypeDescription
    bitwise_txtSTRING