Saturday, March 14, 2020

Variable-length encoding

LEB128 - Wikipedia

LEB128 or Little Endian Base 128 is a form of variable-length code compression used to store an arbitrarily large integer in a small number of bytes. LEB128 is used in the DWARF debug file format[1][2] and the WebAssembly binary encoding for all integer literals.[3]
MSB ------------------ LSB
      10011000011101100101  In raw binary
     010011000011101100101  Padded to a multiple of 7 bits
 0100110  0001110  1100101  Split into 7-bit groups
00100110 10001110 11100101  Add high 1 bits on all but last (most significant) group to form bytes
    0x26     0x8E     0xE5  In hexadecimal

→ 0xE5 0x8E 0x26            Output stream (LSB to MSB)

What is most significant bit or byte? - Definition from

The most significant bit (MSB) is the bit in a multiple-bit binary number with the largest value. This is usually the bit farthest to the left, or the bit transmitted first in a sequence. For example, in the binary number 1000, the MSB is 1, and in the binary number 0111, the MSB is 0.

leb128 · GitHub Topics

wasm-LEB128/unsigned.js at master · shmishtopher/wasm-LEB128

UTF-8 - Wikipedia

No comments: