to bytes
Pack an integer into raw bytes, byte order and all
- BYTES
Every integer, if you squint, is just a sequence of bytes waiting to happen. to bytes from the Basic data handling pack is the node that makes that concrete: you give it an integer, a byte length, a byte order, and a signed flag, and it hands back the raw binary representation. It's the most "systems programming" node in the pack, and if your workflow ever needs to serialize a number into a binary format - writing a header, building a protocol payload, round-tripping with the pack's from bytes - it's exactly what you want.
What it does
A wrapper around Python's int.to_bytes(). The three settings do the real work:
length- INT, minimum1, default4. How many bytes to produce. An integer that doesn't fit in that many bytes raises an error - you can't pack 65536 into a single byte.byteorder-"big"or"little". Big-endian writes the most significant byte first; little-endian writes it last. For cross-system formats, match whatever the receiver expects - mismatched byte order is the classic silent-corruption bug in binary work.signed-"True"or"False". Whether the value uses the top bit as a sign. SignedFalsemeans non-negative only, and gives you the full range of the length (0..255for one byte); signedTrueallows negatives but halves the positive range.
Inputs and outputs
int_value- INT, default0. The number to serialize.length- INT, default4, min1. Output width in bytes.byteorder- enum,big(default) orlittle.signed- enum,False(default) orTrue.- Output
BYTES- the packed bytes.
Note the output type: BYTES is a type this pack defines. Core ComfyUI has nothing that consumes it, so in practice you feed it into the pack's own from bytes node (the pair is built to round-trip) or into whatever custom node in your graph understands raw bytes.
Install
Ships in the Basic data handling pack. ComfyUI Manager → search "Basic data handling" → install → restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
then restart ComfyUI. No dependencies, no models.
The two traps
First, length too small throws rather than truncates - that's a feature, it stops you from silently corrupting data. If you're serializing values of unknown size, compute the length first (the pack's bit length node is a natural helper). Second, signed: if you're porting a format from another tool, match its signedness, not your gut. Get both right and to bytes → from bytes round-trips every value cleanly.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| int_value | INT | 0 | — |
| length | INT | 4 | — |
| byteorder | COMBO | big | 2 options: big, little |
| signed | COMBO | False | 2 options: True, False |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| BYTES | BYTES | — |