NodeCrypto Help

Int to Bytes

Category: Data Conversion & Encoding · Node Type ID: utility-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

Parameter Configuration

Parameter (ID)Type & DefaultVisibility ConditionDescription & Options
Length Mode
lengthMode
select
Default: 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).
  • min: Minimal length — uses the minimum number of bytes required to hold the integer (0 is encoded as 1 byte 0x00).
  • port: Value of the input port — exposes the Length input port and uses the integer received on that port as the target byte width.
  • fixed: Fixed length — uses the constant byte width specified in the Length property.
Length
length
number
Default: 1
Supports Variable Reference ($var: int)
When lengthMode is fixed Target byte count (integer ≥ 0) when Length Mode = fixed. Only visible when Length Mode is fixed.
Endian
endian
select
Default: big
Always visible Byte ordering of the output buffer: big (most significant byte first, network byte order) or little (least significant byte first).
  • big: Big Endian — most significant byte first (e.g., 258 in 2 bytes -> 0x01 0x02).
  • little: Little Endian — least significant byte first (e.g., 258 in 2 bytes -> 0x02 0x01).

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 NamePort IDData TypeRequiredVisibility ConditionDescription
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 NamePort IDData TypeVisibility ConditionDescription
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 CodeDefault Engine MessageTrigger 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.

  1. Set Length Mode to Fixed length, Length to 8, and Endian to Big Endian.
  2. Connect an integer counter to Int; the Bytes output emits an 8-byte big-endian representation.