Skip to content

About

Encode and decode integers with ZigZag encoding from the command line.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@kszongic/zigzag-encode-cli

npm version license

Encode and decode integers using Protocol Buffers zigzag encoding. Zero dependencies.

Zigzag encoding maps signed integers to unsigned integers so that small absolute values have small encoded values:

Signed Encoded
0 0
-1 1
1 2
-2 3
2 4

Install

npm install -g @kszongic/zigzag-encode-cli

Usage

# Encode signed → unsigned
zigzag-encode encode 42      # 84
zigzag-encode encode -1      # 1
zigzag-encode encode 0       # 0

# Decode unsigned → signed
zigzag-encode decode 84      # 42
zigzag-encode decode 1       # -1

# Multiple values
zigzag-encode encode 1 -1 2 -2
# 2
# 1
# 4
# 3

# From stdin
echo "-100" | zigzag-encode encode   # 199

Supports arbitrarily large integers via BigInt.

License

MIT © 2026 kszongic

About

Encode and decode integers with ZigZag encoding from the command line.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages