Bitwise Right Shift Operator
Slide bytes over and see what falls out
- bitwise_txt
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:
text_1andtext_2must decode to equal length - the node raises aValueErrorotherwise. Because the shift amounts come fromtext_2's bytes, each byte of data needs a matching shift byte.- Everything happens on bytes. If you set
datatypetoString, the node shifts raw UTF-8 bytes and tries to decode the result back to text - which can throw aUnicodeDecodeErrorwhen the shifted bytes aren't valid UTF-8. For real bit work, useHexadecimal,Binary, orInteger.
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" withIntegerdatatype is the usual move.datatype- how both inputs and the output are interpreted:String,Hexadecimal,Base64,Integer, orBinary.encoding_format- text encoding forStringdatatype; setOtherand fillother_encoding_formatfor 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.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| text_1 | STRING | Hello World! | The main string to compare against. Accepts format defined in `datatype` |
| text_2 | STRING | Hello World! | The secondary string to compare against. Accepts format defined in `datatype` |
| datatype | COMBO | Binary | The 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_format | COMBO | The encoding format available for text, may yield different results when converting. | |
| other_encoding_formatopt | STRING | If, 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)
| Name | Type | Description |
|---|---|---|
| bitwise_txt | STRING | — |