Reputation: 239
(source: http://webassembly.github.io/spec/core/binary/values.html#integers)
According to my understanding of specification, value 3 should be encoded to 0x03
for u8
. (It satisfies the condition of "if n < 27 ∧ n < 2N")
By the way, the next paragraph says like this:
The side conditions N>7 in the productions for non-terminal bytes of the u and s encodings restrict the encoding’s length. However, “trailing zeros” are still allowed within these bounds. For example, 0x03 and 0x83 0x00 are both well-formed encodings for the value 3 as a u8.
I get 0x83 0x00 by the second equation, but it's for the case of "if n ≥ 27 ∧ N < 7". For value 3, it doesn't satisfy the condition of "n ≥ 27" How can 0x83 0x00
be a well-formed encodings in this case?
Upvotes: 1
Views: 178
Reputation: 36118
You may be interpreting the specification in the wrong direction. It specifies decoding, not encoding. So in the example, n is not the value 3, but the byte value 0x83
. 3 should equal the right-hand side formula "2^7 * m + (n - 2^7)". This is the case because m (the value of the second byte) will be 0.
Upvotes: 2