signed-varint
efficiently store signed integers in varint
Last updated 8 years ago by dominictarr .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install signed-varint 
SYNC missed versions from official npm registry.

signed-varint

store signed integers efficiently, as per protocol-buffers.

For unsigned integers use varint.

Integers are mapped to positive integers, so that positive integers become positive even numbers (n2) and negative integers become positive odd numbers. (n-2 - 1)

This is the same as moving the sign bit from the most significant possition to the least significant. Otherwise, varint will encode negative numbers as large integers.

var varint = require('varint')
var svarint = require('signed-varint')

console.log('unsigned', varint.encode(-1))
console.log('signed', svarint.encode(-1))

//=> unsigned [255,255,255, 15]
//   signed [1]

License

MIT

Current Tags

  • 2.0.1                                ...           latest (8 years ago)

3 Versions

  • 2.0.1                                ...           8 years ago
  • 2.0.0                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (1)

Copyright 2013 - present © cnpmjs.org | Home |