Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6556981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:00:56+00:00 2026-05-25T13:00:56+00:00

I would like the best routine the community can devise which will provide a

  • 0

I would like the best routine the community can devise which will provide a version number string using only 32 bits. The version number will contain three parts: major, minor, and build number. Bonus karma points for answers that include Java source.

Update 1

Ok, so to clear up some confusion the major and minor fields should be represented with one 8-bit byte each and the build number would use the remaining bits.
Major: 8 bits
Minor: 8 bits
Build: 16 bits
The byte order will be little endian.

The tags are to denote that an answer in java and / or c++ would be preferred over python, ruby, etc..

Update 2

Example: take an integer (4 bytes) like 101020 and run it through an algormithmic routine to produce an output string like so: 0.1.2

Java Solution


    public static final int versionToInt(int major, int minor, int build) {
        int ver = (major << 24) | (minor << 16) | build;
    return ver;
    }

    public static final String versionToString(int ver) {
        return String.format("%s.%s.%s", ((ver & 0xff000000) >> 24), ((ver & 0x00ff0000) >> 16), (ver & 0x0000ffff));
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:00:56+00:00Added an answer on May 25, 2026 at 1:00 pm

    Java:

    class Version
    {
        public char major;
        public char minor;
        public short build;
    
        // And the rest of your class definition ...
    }
    

    Edit: So you want to do it with a bit shifts and store it in a 32-bit integer (even though using a class or struct would still use the same amount of storage space)?

    An example function in C would be as follows

    uint32_t MakeVersionNumber( int8_t major, int8_t minor, int16_t build )
    {
       return ((uint32_t)major << 24) | ((uint32_t)minor << 16) | ((uint32_t)build);
    }
    

    Edit 2:

    Riiight I think i get ya. You have a 32-bit number and you want to get a string. So here is an example in C++:

    std::string MakeVersionString( unsigned int ver )
    {
        std::stringstream ss;
        ss << ((ver & 0xff000000) >> 24) << "." << ((ver & 0x00ff0000) >> 16) << "." << (ver & 0x0000ffff);
        return ss.str(); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know which one is the best material that I can
I would like to know what is the best practice between using bind tag
What I would like ask is best illustrated by an example, so bear with
I would like to learn the best practices to employ when creating a database
I would like to learn the best practices in reloading the application state, such
I would like to know the best way to save an image from a
I would like to know the best way to delete records from a live
I would like to know what's the best technique to do single sign-on in
I would like to know what would be the best way to do unit
I would like to know what the best practice for populating a business object

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.