Description
Map one exact signed integer to its unsigned ZigZag value under a declared bit width.
Protocol Buffer integer fields separate a numeric key, signed-value mapping and byte representation. Varint groups carry seven payload bits plus continuation, while ZigZag and sign-extended integer types represent negative values differently.
Map one exact signed integer to its unsigned ZigZag value under a declared bit width.
When to use this tool
Use Protocol Buffers Zigzag Signed Scalar when inspecting one supplied protobuf integer or key-encoding component.
How to use the tool and how it works
- Enter signedDecimal, bits. Use the units and conventions below.
- Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
- Read unsignedDecimal. Use the output convention below.
Require whole bits in [1,64] and an exact signed decimal integer within [-2^(bits-1),2^(bits-1)-1]. Return unsignedDecimal = 2*n for n >= 0, otherwise -2*n-1, as exact decimal text.1
Protobuf separates keys, varints, fixed-width payloads and signed mappings. A local field transformation does not encode a complete message.2
| Input field | Meaning and units | Accepted input |
|---|---|---|
| signedDecimal | Exact signed integer text, with its range determined by bits. | Required. Text; maximum UTF-16 length 8192. Integer syntax: optional + or - and 1-128 decimal digits; leading zeros accepted. Apply the sign restriction above. |
| bits | Signed bit width from one through 64. | Required. Safe integer; minimum 1; maximum 64. |
| Output field | Interpretation | Returned shape |
|---|---|---|
| unsignedDecimal | Unsigned Decimal | Required. Text; maximum UTF-16 length 8192. |
{
"input": {
"signedDecimal": "-2",
"bits": 32
},
"output": {
"unsignedDecimal": "3"
}
} Limitations and assumptions
- This is ZigZag mapping only, not the subsequent varint bytes. The declared signed width is enforced; numeric floating-point input is not substituted for decimal text.
- Inputs must satisfy both the field types and the cross-field conditions above. Invalid input causes an error; a successful false flag or documented placeholder is a different result.
- Numeric calculations use binary floating point unless exact decimal-integer arithmetic is explicitly stated. No hidden measurement tolerance or decimal rounding is added; nonfinite or out-of-contract results are rejected. Numeric signed-zero results are exported as zero.
Alternative or Complementary methods
Use a conforming complete serializer and message schema for full wire encoding, payload validation and interoperability.
References
-
Calculation and input contract: encode/protobuf-zigzag-signed-scalar — tool.io
-
Protocol Buffers wire encoding — Protocol Buffers
Similar or alternative tools
- Varint Terminal Byte From Payload
Return octet = payload, leaving the high continuation bit clear to mark the final seven-bit group.
- Varint Seven Bit Group Writer
Construct one varint octet and lowercase hex spelling from a seven-bit payload and continuation flag.