Skip to content

Instantly share code, notes, and snippets.

@ryohey
Last active November 29, 2019 11:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryohey/8ad61e713e4fdad4b9b12eabb49201e0 to your computer and use it in GitHub Desktop.
Save ryohey/8ad61e713e4fdad4b9b12eabb49201e0 to your computer and use it in GitHub Desktop.
Convert Integer to Variable Length Quantity as an array. JavaScript で整数を可変長数値表現するコードが短く書けた
function varIntBytes(v) {
const r = [v & 0x7f]
while ((v >>= 7) > 0) {
r.unshift(0x80 + (v & 0x7f))
}
return r
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment