Search for a tool
LEB128

Tool to easily convert numbers in LEB128 format or from LEB128 to decimal, binary or hexadecimal. Compatible with signed and unsigned values, fast and accurate conversion online.

Results

LEB128 -

Tag(s) : Character Encoding

Share
Share
dCode and more

dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!


Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!


Feedback and suggestions are welcome so that dCode offers the best 'LEB128' tool for free! Thank you!

LEB128

Decimal to LEB128




LEB128 to decimal





Answers to Questions (FAQ)

What is LEB128 format? (Definition)

LEB128 (Little Endian Base 128) is a compact encoding method used to represent variable-sized integers. This format encodes numbers using groups of 7 bits per byte, which allows for the reduction of small numeric values while still retaining the ability to represent very large integers. There are two main variants: ULEB128 (Unsigned LEB128) for unsigned values and SLEB128 (Signed LEB128) for signed values.

How to encode a number with LEB128?

To encode an integer in LEB128:

— Convert the number to binary (base 2)

Example: The number 1234 is encoded as 10011010010

— Divide the number into 7-bit blocks (and pad with leading 0s if necessary)

Example: 0001001/1010010

— Place the 7 least significant bits (right) in the first byte

— Set the continuation bit (bit 8, most significant) to 1 if another byte follows, otherwise set to 0

— Repeat until all bits are encoded

Example: The first byte contains 11010010 (0xd2), the second 00001001 (0x09). 1234 is coded as 1101001000001001 (0xd209)

If the number is negative, then apply a 2's complement to the input binary number.

How to decode a number encoded in LEB128?

To decode an LEB128 sequence:

— Read the bytes one byte at a time.

— Extract the 7 least significant bits from each byte and concatenate them in reverse order.

— Continue as long as the continuation bit (bit 8, most significant) is set to 1.

— Reconstruct the final binary value from the accumulated bits.

If the number is signed, then apply a 2's complement to the resulting binary value and treat this number as negative.

How to recognize a value encoded in LEB128?

An LEB128 value is recognizable by its binary structure [1.......][1.......]...[0.......]

Each byte has its most significant bit (bit 8) set to 1, except the last one which has this bit set to 0

What are the variants of the LEB128 format?

ULEB128: Encodes unsigned integers (positive)

SLEB128: Encodes signed integers (negative)

Why use LEB128?

Using LEB128 allows you to store numbers of any size (including very large, arbitrary size) while saving memory space for small integers.

What is the difference between LEB128 and VLQ?

VLQ (Variable-Length Quantity) is a similar concept for storing integers. The major difference is that LEB128 is little-endian (least significant bits first), while VLQ is big-endian (most significant bits first).

Source code

dCode retains ownership of the "LEB128" source code. Any algorithm for the "LEB128" algorithm, applet or snippet or script (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, translator), or any "LEB128" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) or any database download or API access for "LEB128" or any other element are not public (except explicit open source licence). Same with the download for offline use on PC, mobile, tablet, iPhone or Android app.
Reminder: dCode is an educational and teaching resource, accessible online for free and for everyone.

Cite dCode

The content of the page "LEB128" and its results may be freely copied and reused, including for commercial purposes, provided that dCode.fr is cited as the source (Creative Commons CC-BY free distribution license).

Exporting the results is free and can be done simply by clicking on the export icons ⤓ (.csv or .txt format) or ⧉ (copy and paste).

To cite dCode.fr on another website, use the link: https://www.dcode.fr/leb128-encoding

In a scientific article or book, the recommended bibliographic citation is: LEB128 on dCode.fr [online website], retrieved on 2025-10-19, https://www.dcode.fr/leb128-encoding

Need Help ?

Please, check our dCode Discord community for help requests!
NB: for encrypted messages, test our automatic cipher identifier!

Questions / Comments

Feedback and suggestions are welcome so that dCode offers the best 'LEB128' tool for free! Thank you!


https://www.dcode.fr/leb128-encoding
© 2025 dCode — The ultimate collection of tools for games, math, and puzzles.
â–˛  
Feedback