Int to Bytes
Converts an unsigned integer to bytes (length: minimal, fixed, or from the Length port)
Overview
Serializes an unsigned integer (Int / bigint, ≥ 0) into a raw byte array (Uint8Array) using the selected Endian byte order (Big-Endian or Little-Endian) and Length Mode.
You can choose between three length modes: Minimal length (uses the fewest bytes needed to represent the value, with 0 encoded as 1 byte 0x00), Fixed length (uses the constant byte count configured in the Length parameter), or Value of the input port (exposes a conditional Length input port so the byte width can be computed dynamically at runtime).
When to Use
- Encoding integer counters, sequence numbers, timestamps, or message lengths into fixed-width 4-byte (32-bit) or 8-byte (64-bit) big-endian/little-endian fields for protocol packets or nonces.
- Converting large bigints (such as RSA or Diffie-Hellman integers) into minimal-length byte arrays.
Parameter Configuration
| Parameter (ID) | Type & Default | Visibility Condition | Description & Options |
|---|---|---|---|
Length ModelengthMode |
selectDefault: min |
Always visible | Controls how the output byte length is determined: min (minimal byte count; 0 produces 1 byte), port (reads the target byte length from the conditional Length input port), or fixed (uses the Length parameter below).
|
Lengthlength |
numberDefault: 1 |
When lengthMode is fixed |
Target byte count (integer ≥ 0) when Length Mode = fixed. Only visible when Length Mode is fixed. |
Endianendian |
selectDefault: big |
Always visible | Byte ordering of the output buffer: big (most significant byte first, network byte order) or little (least significant byte first).
|
Port I/O Specification
See Ports & Connections for general wiring rules, data type colors, and dynamic port creation.
Input Ports
Port Nature: Fixed Input Ports (2 total).
| Port Name | Port ID | Data Type | Required | Visibility Condition | Description |
|---|---|---|---|---|---|
Value |
in |
Int |
Required | Always visible | |
Length |
length |
Int |
Optional | Always visible | Target output byte length (Int ≥ 0). Only visible and required when Length Mode = port. |
Output Ports
Port Nature: Fixed Output Ports (1 total).
| Port Name | Port ID | Data Type | Visibility Condition | Description |
|---|---|---|---|---|
Bytes |
out |
Bytes |
Always visible |
Error Cases
When any of the following conditions occurs at runtime, this node transitions to an ERROR state and downstream nodes connected to its outputs do not execute.
| Error Code | Default Engine Message | Trigger Condition |
|---|---|---|
BYTES_INT_OVERFLOW |
The integer cannot be represented with the given length and sign | Raised when the integer value cannot fit within the specified fixed or port byte length. |
BYTES_INVALID_ARGUMENT |
Invalid argument value | Raised when an argument (such as bit shift count, byte length, or negative integer) is invalid or negative. |
Examples
Encoding a 64-bit Big-Endian Packet Counter
Convert an integer counter into an 8-byte big-endian buffer.
- Set Length Mode to
Fixed length, Length to8, and Endian toBig Endian. - Connect an integer counter to
Int; theBytesoutput emits an 8-byte big-endian representation.