# Bytes pack integers

`bytes-pack-integers` · version 1.0.0 · Other utilities · free, no key needed

Pack exact decimal integer strings into raw hex bytes with explicit widths, endianness, and range checks.

**Use when you need to: bitwise integer operations unsigned hex encode endian · pack integers into little endian bytes · write protocol integer fields as hex.**

## Decide before calling

Read the [versioned contract](/v1/tools/bytes-pack-integers/versions/1.0.0) and the supported scope below. Reuse `bytes-pack-integers@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `bytes-pack-integers@1.0.0` for bitwise integer operations unsigned hex encode endian. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- bitwise integer operations unsigned hex encode endian
- pack integers into little endian bytes
- write protocol integer fields as hex
- Python struct pack integers to hexadecimal
- encode signed i16 and unsigned u32 bytes
- make firmware raw bytes from integer values
- range check integer binary fields

## Not supported

- bitwise arithmetic or masks
- floating-point fields
- native alignment or host byte order

## Behavior

- Inputs and outputs preserve 64-bit integers exactly as strings; standard_version is IEEE 754-2019; Python 3.12 struct.
- Layout uses the same named fields or Python struct subset as bytes-unpack-integers; x writes 00 and consumes no value; = is deterministic little endian.
- Each integer is checked against its signed or unsigned field range before two’s-complement encoding.
- max_input_bytes bounds the UTF-8 byte length of JSON.stringify(input), including keys, punctuation, and every field. Field bounds apply together with this whole-input bound.
- max_hex_chars bounds the input hex string for unpacking and the output hex string for packing, allowing at most 256 raw bytes. max_layout_bytes bounds a string layout in UTF-8.

## Input

- `values` (array of string, required): max items 64; each min length 1; each max length 21; each pattern `^(0|-?[1-9][0-9]*)$`
- `layout` (string or array of string, required)

## Output

- `standard_version` (string, required)
- `byte_length` (integer, required): min 1; max 256
- `hex` (string, required): min length 2; max length 512; pattern `^[0-9a-f]+$`

## Limits

- max input bytes: 4096
- max hex chars: 512
- max layout bytes: 130
- max items: 64
- max output bytes: 8192

## Example

Request input:

```json
{
  "values": [
    "305419896"
  ],
  "layout": [
    "u32le"
  ]
}
```

Response:

```json
{
  "result": {
    "standard_version": "IEEE 754-2019; Python 3.12 struct",
    "byte_length": 4,
    "hex": "78563412"
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "bytes-pack-integers",
  "version": "1.0.0",
  "input": {
    "values": [
      "305419896"
    ],
    "layout": [
      "u32le"
    ]
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/bytes-pack-integers/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"values":["305419896"],"layout":["u32le"]}'
```

The machine-readable contract is at [/v1/tools/bytes-pack-integers/versions/1.0.0](/v1/tools/bytes-pack-integers/versions/1.0.0).

### CLI

```sh
node cli.mjs run bytes-pack-integers 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Bytes unpack integers](/tools/bytes-unpack-integers): Unpack raw hex bytes into exact signed or unsigned integer strings using an explicit endian layout.
- [Base64url encode](/tools/base64url-encode): Encode supplied UTF-8 text or hexadecimal bytes as base64url and return the encoded string.
- [Bytes format human](/tools/bytes-format-human): Format an exact byte count as both SI and IEC strings and return the rounding mode used.
- [Base64url decode](/tools/base64url-decode): Decode base64url to UTF-8 text or lowercase hex and return the requested value.
- [Float ieee754 convert](/tools/float-ieee754-convert): Convert binary16/32/64 decimal values and exact hex bits, returning fields, class, and the exact stored decimal.
- [Html to plain text](/tools/html-to-plain-text): Strip HTML and script/style text, decode supported references; collapse whitespace including inside pre elements.
