Skip to content

kszongic/zigzag-encode-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

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

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors