Skip to content

zigzagDecode

The inverse of zigzagEncode: maps an unsigned 64-bit zigzag value back to the signed integer.

Available since v3.1.8

import { zigzagDecode } from '@helpers4/binary';
// or, from the all-in-one package (same code, one install):
import { zigzagDecode } from 'helpers4/binary';
zigzagDecode(value: bigint): bigint
ParameterTypeDescription
valuebigintAn unsigned integer in the 64-bit range

bigint — The signed integer

The inverse of zigzagEncode.

zigzagDecode(1n) // => -1n
zigzagDecode(2n) // => 1n

Read the unsigned varint first, then undo the zigzag mapping.

zigzagDecode(300n) // => 150n

View source on GitHub