Store a Semantic Versioning String in a 32-Bit Integer

Semantic Versioning is a specification, which describes how version strings should be handled. It works by having MAJOR, MINOR and PATCH versions in a dot-separated string. Example:



I needed to store this string in a single 32-bit integer due to system limitations, so I wrote two handy, well-documented functions in ES6. Let’s convert the version string “2.5.3” into an integer:

let numericVersion = convertVersionToInt32('2.5.3'); // 3150850
let version = convertInt32VersionToString(numericVersion); // "2.5.3"

One thought on “Store a Semantic Versioning String in a 32-Bit Integer

  1. Demian Marty

    a little remark:
    in order to get an ascending integer, the parts have to be reversed before they are shifted, otherwise the version will be read upside down.


Leave a Reply

Your email address will not be published. Required fields are marked *