ComfyUI Node

to bytes

Pack an integer into raw bytes, byte order and all

By StableLlama·Created about a year ago·Updated about 15 hours ago· 48
to bytes
    • BYTES
    int_value0
    length4
    byteorderbig
    signedFalse

    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, minimum 1, default 4. 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. Signed False means non-negative only, and gives you the full range of the length (0..255 for one byte); signed True allows negatives but halves the positive range.

    Inputs and outputs

    • int_value - INT, default 0. The number to serialize.
    • length - INT, default 4, min 1. Output width in bytes.
    • byteorder - enum, big (default) or little.
    • signed - enum, False (default) or True.
    • 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 bytesfrom bytes round-trips every value cleanly.

    CategoryBasic/INT

    Inputs (4)

    NameTypeDefaultDescription
    int_valueINT0
    lengthINT4
    byteorderCOMBObig2 options: big, little
    signedCOMBOFalse2 options: True, False

    Outputs (1)

    NameTypeDescription
    BYTESBYTES