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:

MAJOR.MINOR.PATCH

2.5.3

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"

Leave a Reply

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