This article has not yet been rated on Wikipedia's
content assessment scale. It is of interest to the following WikiProjects: | ||||||||||||||||||
|
Does this sentence mean that no one considered this encoding of integers (in a verifiable way) before the standard MIDI file format was defined in the early 1980s? If so, I am very surprised. -- fcp2007 ( talk) 21:06, 13 July 2008 (UTC)
This page should probably be titled "base-128 encoding" or similar, and more generally describe all variations on the theme. (1 or 0 as stop bit, most significant bit group first or last significant, comparison to UTF-8 etc.) —Preceding unsigned comment added by 213.136.42.60 ( talk) 13:49, 18 November 2010 (UTC)
Another option is to encode the length n with VLQ and then interpret the following n bytes as a number.
Space usage:
Solomon Ucko ( talk) 21:59, 4 February 2019 (UTC)
There are countless examples of this format throughout various projects, which should be added to the main article, and related articles linking back somehow:
There is currently a template-tag to move LEB128 to this page, but I think this page should be moved to LEB128. Andyjrobb ( talk) 22:35, 19 June 2019 (UTC)
LEB128 uses two's complement to represent signed numbers. In this scheme of representation, n bits encodes a range from -2n to 2n-1. I guess it should be -2n - 1 to 2n - 1-1. 178.64.56.11 ( talk) 01:20, 24 September 2021 (UTC)
I think that the table ( Variable-length quantity#Examples) needs a review. There appear to be many errors in it (such as 7 digit bytes in the row for 134217728, and a "4" in the varint binary representation of 8192).
I've written a script from first principles to generate what I believe to be the correct values, please see the output below.
1 Integer (decimal) | 2 Integer (hexadecimal) | 3 Integer (binary) | 4 Variable-length quantity (hexadecimal) | 5 Variable-length quantity (binary) |
---|---|---|---|---|
0 | 0x00000000 | 00000000 | 0x00 | 00000000 |
127 | 0x0000007F | 01111111 | 0x7F | 01111111 |
128 | 0x00000080 | 10000000 | 0x81 0x00 | 10000001 00000000 |
8192 | 0x00002000 | 00100000 00000000 | 0xC0 0x00 | 11000000 00000000 |
16383 | 0x00003FFF | 00111111 11111111 | 0xFF 0x7F | 11111111 01111111 |
16384 | 0x00004000 | 01000000 00000000 | 0x81 0x80 0x00 | 10000001 10000000 00000000 |
2097151 | 0x001FFFFF | 00011111 11111111 11111111 | 0xFF 0xFF 0x7F | 11111111 11111111 01111111 |
2097152 | 0x00200000 | 00100000 00000000 00000000 | 0x81 0x80 0x80 0x00 | 10000001 10000000 10000000 00000000 |
134217728 | 0x08000000 | 00001000 00000000 00000000 00000000 | 0xC0 0x80 0x80 0x00 | 11000000 10000000 10000000 00000000 |
268435455 | 0x0FFFFFFF | 00001111 11111111 11111111 11111111 | 0xFF 0xFF 0xFF 0x7F | 11111111 11111111 11111111 01111111 |
JSFiddle with the source that generated it: https://jsfiddle.net/w6jL5qy3/
Additionally, I don't see the value in including the two Hexadecimal columns - its just confusing and detracts from the example. - Chieftain Alex 20:15, 18 April 2023 (UTC)
This article has not yet been rated on Wikipedia's
content assessment scale. It is of interest to the following WikiProjects: | ||||||||||||||||||
|
Does this sentence mean that no one considered this encoding of integers (in a verifiable way) before the standard MIDI file format was defined in the early 1980s? If so, I am very surprised. -- fcp2007 ( talk) 21:06, 13 July 2008 (UTC)
This page should probably be titled "base-128 encoding" or similar, and more generally describe all variations on the theme. (1 or 0 as stop bit, most significant bit group first or last significant, comparison to UTF-8 etc.) —Preceding unsigned comment added by 213.136.42.60 ( talk) 13:49, 18 November 2010 (UTC)
Another option is to encode the length n with VLQ and then interpret the following n bytes as a number.
Space usage:
Solomon Ucko ( talk) 21:59, 4 February 2019 (UTC)
There are countless examples of this format throughout various projects, which should be added to the main article, and related articles linking back somehow:
There is currently a template-tag to move LEB128 to this page, but I think this page should be moved to LEB128. Andyjrobb ( talk) 22:35, 19 June 2019 (UTC)
LEB128 uses two's complement to represent signed numbers. In this scheme of representation, n bits encodes a range from -2n to 2n-1. I guess it should be -2n - 1 to 2n - 1-1. 178.64.56.11 ( talk) 01:20, 24 September 2021 (UTC)
I think that the table ( Variable-length quantity#Examples) needs a review. There appear to be many errors in it (such as 7 digit bytes in the row for 134217728, and a "4" in the varint binary representation of 8192).
I've written a script from first principles to generate what I believe to be the correct values, please see the output below.
1 Integer (decimal) | 2 Integer (hexadecimal) | 3 Integer (binary) | 4 Variable-length quantity (hexadecimal) | 5 Variable-length quantity (binary) |
---|---|---|---|---|
0 | 0x00000000 | 00000000 | 0x00 | 00000000 |
127 | 0x0000007F | 01111111 | 0x7F | 01111111 |
128 | 0x00000080 | 10000000 | 0x81 0x00 | 10000001 00000000 |
8192 | 0x00002000 | 00100000 00000000 | 0xC0 0x00 | 11000000 00000000 |
16383 | 0x00003FFF | 00111111 11111111 | 0xFF 0x7F | 11111111 01111111 |
16384 | 0x00004000 | 01000000 00000000 | 0x81 0x80 0x00 | 10000001 10000000 00000000 |
2097151 | 0x001FFFFF | 00011111 11111111 11111111 | 0xFF 0xFF 0x7F | 11111111 11111111 01111111 |
2097152 | 0x00200000 | 00100000 00000000 00000000 | 0x81 0x80 0x80 0x00 | 10000001 10000000 10000000 00000000 |
134217728 | 0x08000000 | 00001000 00000000 00000000 00000000 | 0xC0 0x80 0x80 0x00 | 11000000 10000000 10000000 00000000 |
268435455 | 0x0FFFFFFF | 00001111 11111111 11111111 11111111 | 0xFF 0xFF 0xFF 0x7F | 11111111 11111111 11111111 01111111 |
JSFiddle with the source that generated it: https://jsfiddle.net/w6jL5qy3/
Additionally, I don't see the value in including the two Hexadecimal columns - its just confusing and detracts from the example. - Chieftain Alex 20:15, 18 April 2023 (UTC)