<s>
LEB128	B-Algorithm
or	O
Little	B-Algorithm
Endian	I-Algorithm
Base	I-Algorithm
128	I-Algorithm
is	O
a	O
variable-length	B-Algorithm
code	I-Algorithm
compression	O
used	O
to	O
store	O
arbitrarily	B-Algorithm
large	I-Algorithm
integers	I-Algorithm
in	O
a	O
small	O
number	O
of	O
bytes	O
.	O
</s>
<s>
LEB128	B-Algorithm
is	O
used	O
in	O
the	O
DWARF	O
debug	O
file	O
format	O
and	O
the	O
WebAssembly	B-Language
binary	O
encoding	O
for	O
all	O
integer	O
literals	O
.	O
</s>
<s>
LEB128	B-Algorithm
format	O
is	O
very	O
similar	O
to	O
variable-length	O
quantity	O
(	O
VLQ	O
)	O
format	O
;	O
the	O
primary	O
difference	O
is	O
that	O
LEB128	B-Algorithm
is	O
little-endian	O
whereas	O
variable-length	O
quantities	O
are	O
big-endian	O
.	O
</s>
<s>
There	O
are	O
2	O
versions	O
of	O
LEB128	B-Algorithm
:	O
unsigned	O
LEB128	B-Algorithm
and	O
signed	O
LEB128	B-Algorithm
.	O
</s>
<s>
The	O
decoder	O
must	O
know	O
whether	O
the	O
encoded	O
value	O
is	O
unsigned	O
LEB128	B-Algorithm
or	O
signed	O
LEB128	B-Algorithm
.	O
</s>
<s>
To	O
encode	O
an	O
unsigned	O
number	O
using	O
unsigned	O
LEB128	B-Algorithm
(	O
ULEB128	B-Algorithm
)	O
first	O
represent	O
the	O
number	O
in	O
binary	O
.	O
</s>
<s>
Unsigned	O
LEB128	B-Algorithm
and	O
VLQ	O
(	O
variable-length	O
quantity	O
)	O
both	O
compress	O
any	O
given	O
integer	O
into	O
not	O
only	O
the	O
same	O
number	O
of	O
bits	O
,	O
but	O
exactly	O
the	O
same	O
bits	O
—	O
the	O
two	O
formats	O
differ	O
only	O
in	O
exactly	O
how	O
those	O
bits	O
are	O
arranged	O
.	O
</s>
<s>
A	O
signed	O
number	O
is	O
represented	O
similarly	O
:	O
Starting	O
with	O
an	O
-bit	O
two	B-General_Concept
's	I-General_Concept
complement	I-General_Concept
representation	O
,	O
where	O
is	O
a	O
multiple	O
of	O
7	O
,	O
the	O
number	O
is	O
broken	O
into	O
groups	O
as	O
for	O
the	O
unsigned	O
encoding	O
.	O
</s>
<s>
A	O
straightforward	O
scalar	O
implementation	O
of	O
LEB128	B-Algorithm
decoding	O
is	O
fairly	O
slow	O
,	O
even	O
more	O
so	O
on	O
modern	O
hardware	O
where	O
branch	O
misprediction	O
is	O
relatively	O
expensive	O
.	O
</s>
<s>
The	O
"	O
Vectorized	O
VByte	O
Decoding	O
"	O
paper	O
presented	O
"	O
Masked	O
VByte	O
"	O
,	O
which	O
demonstrated	O
speeds	O
of	O
650-2700	O
million	O
integers	O
per	O
second	O
on	O
commodity	O
Haswell	B-Device
hardware	O
,	O
depending	O
on	O
encoding	O
density	O
.	O
</s>
<s>
This	O
stream	O
encoding	O
separates	O
the	O
control	O
stream	O
from	O
the	O
encoded	O
data	O
,	O
so	O
is	O
not	O
binary	O
compatible	O
with	O
LEB128	B-Algorithm
.	O
</s>
<s>
The	O
Android	B-Application
project	O
uses	O
LEB128	B-Algorithm
in	O
its	O
Dalvik	O
Executable	O
Format	O
(	O
.dex	O
)	O
file	O
format	O
.	O
</s>
<s>
The	O
DWARF	O
file	O
format	O
uses	O
both	O
unsigned	O
and	O
signed	O
LEB128	B-Algorithm
encoding	O
for	O
various	O
fields	O
.	O
</s>
<s>
LLVM	B-Application
,	O
in	O
its	O
Coverage	O
Mapping	O
Format	O
LLVM	B-Application
's	O
implementation	O
of	O
LEB128	B-Algorithm
encoding	O
and	O
decoding	O
is	O
useful	O
alongside	O
the	O
pseudocode	O
above	O
.	O
</s>
<s>
Minecraft	B-Application
uses	O
LEB128	B-Algorithm
in	O
its	O
protocol	O
for	O
measuring	O
lengths	O
of	O
data	O
within	O
packets	O
.	O
</s>
<s>
The	O
mpatrol	O
debugging	O
tool	O
uses	O
LEB128	B-Algorithm
in	O
its	O
tracing	O
file	O
format	O
.	O
</s>
<s>
osu	B-Application
!	I-Application
</s>
<s>
uses	O
LEB128	B-Algorithm
in	O
its	O
osu	B-Application
!	I-Application
</s>
<s>
W3C	O
Efficient	B-Language
XML	I-Language
Interchange	I-Language
(	O
EXI	O
)	O
represents	O
unsigned	O
integers	O
using	O
LEB128	B-Algorithm
,	O
in	O
exactly	O
the	O
same	O
way	O
as	O
described	O
here	O
.	O
</s>
<s>
Human	B-General_Concept
interface	I-General_Concept
device	I-General_Concept
report	O
descriptor	O
bytes	O
use	O
a	O
byte-count	O
bitfield	O
of	O
2	O
bits	O
to	O
encode	O
the	O
size	O
of	O
the	O
following	O
integer	O
of	O
zero	O
,	O
one	O
,	O
two	O
,	O
or	O
four	O
bytes	O
,	O
always	O
little	O
endian	O
.	O
</s>
<s>
The	O
LLVM	B-Application
bitcode	O
file	O
format	O
uses	O
a	O
similar	O
technique	O
except	O
that	O
the	O
value	O
is	O
broken	O
into	O
groups	O
of	O
bits	O
of	O
context-dependent	O
size	O
,	O
with	O
the	O
highest	O
bit	O
indicating	O
a	O
continuation	O
,	O
instead	O
of	O
a	O
fixed	O
7	O
bits	O
.	O
</s>
<s>
Protocol	B-Protocol
Buffers	I-Protocol
(	O
Protobuf	B-Protocol
)	O
uses	O
the	O
same	O
encoding	O
for	O
unsigned	O
integers	O
,	O
but	O
encode	O
signed	O
integers	O
by	O
prepending	O
the	O
sign	O
as	O
the	O
least	O
significant	O
bit	O
.	O
</s>
