Length-Field Encoder
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.
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).