Skip to content

Main content

Protocol Buffers Zigzag Signed Scalar Tool

Encode one bounded signed integer with Protocol Buffers ZigZag mapping; not varint byte serialization.

Loading tool…

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

  1. Enter signedDecimal, bits. Use the units and conventions below.
  2. Run the tool. Correct any format, range, or cross-field input error before interpreting the output.
  3. 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 fieldMeaning and unitsAccepted input
signedDecimalExact 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.
bitsSigned bit width from one through 64.Required. Safe integer; minimum 1; maximum 64.
Output fieldInterpretationReturned shape
unsignedDecimalUnsigned DecimalRequired. Text; maximum UTF-16 length 8192.
json
{
  "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

  1. Calculation and input contract: encode/protobuf-zigzag-signed-scalar — tool.io

  2. Protocol Buffers wire encoding — Protocol Buffers

Similar or alternative tools