Ambimat GroupAmbimatAmbiSecureSIMAuthAmbiAutomationEngineering BlogAhmedabad · India · Est. 1982
Encoding utility

Length-field encoder for BER-TLV

Convert an integer length into the binary length field used by various protocols: BER long-form (X.690), GP DGI long-form, plain u8, and u16 in big-endian and little-endian. The right format the first time saves a lot of debugging.

Client-sideBER / DGI / u8 / u16

How to use this tool

What it does

Converts an integer length into the binary length field used by BER long-form (X.690), GlobalPlatform DGI long-form, and plain u8/u16 in both byte orders.

When to use it

Use it when hand-building a TLV or DGI structure and you need the exact length prefix bytes for a value, rather than guessing the long-form encoding.

Worked example

Enter 300 and BER long-form renders 82 01 2C (two length bytes flagged by 0x82).

Input

Result

Type something to convert.
All encoding runs locally.

BER vs DGI vs raw

BER (X.690) length: short form when ≤ 127; long form is 0x80|N followed by N length bytes. DGI (GlobalPlatform Data Group Identifier) length: short when < 0xFF; long form is 0xFF followed by 2 length bytes. Raw u8/u16 just write the value at the chosen width.

Spec

X.690 (BER lengths) and GP Card Specification 2.3.1 (DGI).

Companion tool

TLV parsing of what you just wrote.

TLV parser →

Companion tool

Need BE/LE for raw fields?

Endian converter →

Frequently asked questions

Why are there several length encodings?

Because different layers chose differently. BER uses short and long form, DGI uses its own long form, and many proprietary protocols just use a fixed one- or two-byte field.

What is DGI long form?

A Data Grouping Identifier convention where a length of 255 or more is written as 0xFF followed by two big-endian bytes. It appears throughout card personalisation payloads.

When do I need two bytes rather than one?

As soon as the value can reach 256. Sizing a field to the maximum the specification allows rather than to today's data is what prevents a silent truncation later.

Does byte order matter for a length field?

Yes, and it is protocol-specific. BER and DGI are big-endian; several proprietary formats are little-endian, which is why this tool shows both.

Does anything I paste leave my browser?

Nothing. The tool is entirely client-side: the page ships a static script, does no network calls, and never transmits what you paste. You can confirm it by opening the network tab, or by loading the page and then going offline.