How to use this calculator
Map a signed integer to an unsigned ZigZag value and report its base-128 varint length.
- Enter Signed 64-bit integer in decimal. Match the units shown beside each field and review the result together with the assumptions below.
- Read the worked example below to check the expected input format and result.
- Compare another scenario by changing one input at a time. Use Reset to return to the starting values.
Signed ZigZag varint mapping explained
Map a signed integer to an unsigned ZigZag value and report its base-128 varint length.
How the calculation works
n≥0 ? 2n : −2n−1
ZigZag maps a signed integer n to 2n for n≥0 and −2n−1 for n<0, then the unsigned result is split into base-128 varint groups. Uses signed 64-bit input limits and exact integer arithmetic.
Set up the calculation
n— Signed 64-bit integer in decimal- Enter a signed decimal integer in the signed 64-bit range. The ZigZag map converts it to an unsigned value before varint byte-length calculation.
Limits of this model
Uses signed 64-bit input limits and exact integer arithmetic. This is the sint encoding convention, not plain negative int encoding.
Check this example
Signed 64-bit integer in decimal = -123.
- ZigZag unsigned value: 245
- Unsigned varint length: 2 bytes
Interpreting the result
The signed value −123 maps to unsigned 245, which occupies two base-128 varint bytes. This is the ZigZag transform used with signed varint encoding, not a plain signed-integer byte layout.
Frequently asked questions
Why map negatives?
Small negative and positive magnitudes both become small unsigned values.
How does −1 map?
It maps to 1.
Is this two’s complement storage?
No, it is a separate wire-encoding transformation.
How do I use the Signed ZigZag varint mapping calculator?
Enter Signed 64-bit integer in decimal. Match the units shown beside each field and review the result together with the assumptions below.
What is a worked example of Signed ZigZag varint mapping?
Signed 64-bit integer in decimal = -123. ZigZag unsigned value: 245 Unsigned varint length: 2 bytes
Method reference: Protocol Buffers signed integers.
Read our calculation methodology.