• Blog
  • Info Support
  • Career
  • Training
  • International Group
  • Info Support
  • Blog
  • Career
  • Training
  • International Group
  • Search
logo InfoSupport
  • Latest blogs
  • Popular blogs
  • Experts
      • Alles
      • Bloggers
      • Speakers
  • Meet us
  • About us
    • nl
    • en
    • .NET
    • Advanced Analytics
    • Agile
    • Akka
    • Alexa
    • Algorithms
    • Api's
    • Architectuur
    • Artificial Intelligence
    • ATDD
    • Augmented Reality
    • AWS
    • Azure
    • Big Data
    • Blockchain
    • Business Intelligence
    • Cloud
    • Code Combat
    • Cognitive Services
    • Communicatie
    • Containers
    • Continuous Delivery
    • CQRS
    • Cyber Security
    • Dapr
    • Data
    • Data & Analystics
    • Data Science
    • Data Warehousing
    • Databricks
    • DevOps
    • Digital Days
    • Docker
    • eHealth
    • Enterprise Architecture
    • Hacking
    • Infrastructure & Hosting
    • Innovatie
    • Integration
    • Internet of Things
    • Java
    • Machine Learning
    • Microservices
    • Microsoft
    • Microsoft Bot Framework
    • Microsoft Data Platform
    • Mobile Development
    • Mutation Testing
    • Open source
    • Pepper
    • Power BI
    • Privacy & Ethiek
    • Python
    • Quality Assistance & Test
    • Quality Assurance & Test
    • Requirements Management
    • Scala
    • Scratch
    • Security
    • SharePoint
    • Software Architecture
    • Software development
    • Software Factory
    • SQL Server
    • SSL
    • Start-up
    • Startup thinking
    • Stryker
    • Test Quality
    • Testing
    • TLS
    • TypeScript
    • Various
    • Web Development
    • Web-scale IT
    • Xamarin
    • Alles
    • Bloggers
    • Speakers
Home » A primer on VLQ
  • A primer on VLQ

    • By Daan van Berkel
    • Java 7 years ago
    • Java 0 comments
    • Java Java
    A primer on VLQ

    A primer on VLQ

    Variable-Length Quantity (VLQ) is an way of representing arbitrarly
    large integers in bytes. In this blog post we will explore the
    details of how this is achieved.

    Table of Contents

    • 1 Representation Problem
    • 2 VLQ
    • 3 Example
    • 4 Variations
    • 5 Conclusion

    1 Representation Problem

    Lets say you are representing a music score. You need to represent the
    duration of various notes. For each note you will tell how many
    milliseconds it lasts. Although this story is apocryphal it offers a
    nice conundrum: how do you represent numbers on an open ended scale?

    2 VLQ

    One way of doing this is Variable-Length Quantity, a code that uses a
    a variable amount of bytes and a such is amendable to use in a
    computer.

    VLQ is composed of a number of octets, i.e. eight bits. The most
    significant bit of an octet is used to signal if an other octet
    follows. The least significant bits of all octets together form the
    integer.

    3 Example

    Lets say I want to represent the number 3435 in VLQ. 3435 in
    binary is 110101101011. We can not fit this in a byte. So we will
    chop it up from the end in 7-bit blocks

    Septet 7 6 5 4 3 2 1
    #1 1 1 0 1 0 1 1
    #2 0 0 1 1 0 1 0

    Now we prepend all but the last with a 1-bit to indicate that an octet
    follows and prepend a 0-bit to the last, signalling the final octet.

    Octet 8 7 6 5 4 3 2 1
    #1 0 1 1 0 1 0 1 1
    #2 1 0 0 1 1 0 1 0

    Finally we concatenate them, most significant octet first, into
    1001101001101011. An implementation in java is provided.

    4 Variations

    There are a few variations on VLQ possible. First and foremost is the
    order of octets. We agreed to send the most significant octet first,
    but you can switch the order around. You would have to change which
    groups get a continuation bit prepended, but all in all it is not
    very different.

    A more drastic change is to represent both positive and negative
    numbers. In the current code there is no room to encode a sign for
    the number. So we need to free up a bit to encode the sign. One way
    of doing this is to keep the most significant bit as a continuation
    bit, i.e. it signals if an other octet follows. Then use the next
    most significant bit to encode the sign of the number.

    Under this representation -3435 would be represented as
    1111010101101011.

    5 Conclusion

    Variable-Length Quantity is a encoding that enables representation of
    arbitrarly large integers that is easily amendable to computer
    manipulation.

    Share this

Daan van Berkel

View profile

Related IT training

Go to training website

Related Consultancy solutions

Go to infosupport.com

Related blogs

  • Do you know Java? Care to prove it?

    Do you know Java? Care to prove it? Hanno Embregts - 3 months ago

  • Deploy je JDK 11 applicatie op je eigen Java 17 runtime

    Deploy je JDK 11 applicatie op je eigen Java 17 runtime Jelle Spoelders - 5 months ago

  • Explaining software development to a class of 6-year ol…

    Explaining software development to a class of 6-year ol… Hanno Embregts - 6 months ago

Related downloads

  • Beslisboom voor een rechtmatig ‘kopietje productie’

  • Klantreferentie: Remmicom zet wetgeving om in intellige…

  • Klantreferentie RDW: Samenwerken voor veilig en vertrou…

  • Klantreferentie BeFrank: Strategische IT voor een innov…

  • Wie durft te experimenteren met data in de zorg?

Related videos

  • mijnverzekeringenopeenrij.nl

    mijnverzekeringenopeenrij.nl

  • Winnaar | Innovation Projects 2017

    Winnaar | Innovation Projects 2017

  • Explore | Info Support & HAN & Poliskluis

    Explore | Info Support & HAN & Poliskluis

  • LifeApps bij HagaZiekenhuis

    LifeApps bij HagaZiekenhuis

  • Info Support | Bedrijfsfilm

    Info Support | Bedrijfsfilm

Nieuwsbrief

* verplichte velden

Contact

  • Head office NL
  • Kruisboog 42
  • 3905 TG Veenendaal
  • T +31 318 552020
  • Call
  • Mail
  • Directions
  • Head office BE
  • Generaal De Wittelaan 17
  • bus 30 2800 Mechelen
  • T +32 15 286370
  • Call
  • Mail
  • Directions

Follow us

  • Twitter
  • Facebook
  • Linkedin
  • Youtube

Newsletter

Sign in

Extra

  • Media Library
  • Disclaimer
  • Algemene voorwaarden
  • ISHBS Webmail
  • Extranet
Beheer cookie toestemming
Deze website maakt gebruik van Functionele en Analytische cookies voor website optimalisatie en statistieken.
Functioneel
Altijd actief
De technische opslag of toegang is strikt noodzakelijk voor het legitieme doel het gebruik mogelijk te maken van een specifieke dienst waarom de abonnee of gebruiker uitdrukkelijk heeft gevraagd, of met als enig doel de uitvoering van de transmissie van een communicatie over een elektronisch communicatienetwerk.
Voorkeuren
De technische opslag of toegang is noodzakelijk voor het legitieme doel voorkeuren op te slaan die niet door de abonnee of gebruiker zijn aangevraagd.
Statistieken
De technische opslag of toegang die uitsluitend voor statistische doeleinden wordt gebruikt. De technische opslag of toegang die uitsluitend wordt gebruikt voor anonieme statistische doeleinden. Zonder dagvaarding, vrijwillige naleving door uw Internet Service Provider, of aanvullende gegevens van een derde partij, kan informatie die alleen voor dit doel wordt opgeslagen of opgehaald gewoonlijk niet worden gebruikt om je te identificeren.
Marketing
De technische opslag of toegang is nodig om gebruikersprofielen op te stellen voor het verzenden van reclame, of om de gebruiker op een website of over verschillende websites te volgen voor soortgelijke marketingdoeleinden.
Beheer opties Beheer diensten Beheer leveranciers Lees meer over deze doeleinden
Voorkeuren
{title} {title} {title}