Search code examples
c++3dsmax

How to reverse a combined flags result to flags?


I'm developing a 3ds max simple plugin. There is a function which returns a flag called "MAX_Version"

It's a combine of 3 enum like flags...

  1. 3ds MAX Release Number
  2. 3ds Max SDK current version number
  3. 3ds Max revision of the SDK for a given API

Here's the result and final value :

#define VERSION_3DSMAX ((MAX_RELEASE<<16)+(MAX_API_NUM<<8)+MAX_SDK_REV)

Here's the defines :

#define MAX_RELEASE      MAX_RELEASE_R22    /// Value of MAX_RELEASE_R22 is 22000
#define MAX_API_NUM      MAX_API_NUM_R220   /// Value of MAX_API_NUM_R220 is 55
#define MAX_SDK_REV                 0 

Now there's a lot of them defined in 3ds max SDK header :

//! 3ds Max R18 (2016) Preview release id
#define MAX_RELEASE_R18_PREVIEW     17900
//! 3ds Max R18 (2016) release id
#define MAX_RELEASE_R18     18000
//! 3ds Max R19 (2017) Preview release id
#define MAX_RELEASE_R19_PREVIEW     18900
//! 3ds Max R19 (2017) release id
#define MAX_RELEASE_R19     19000
//! 3ds Max R20 (2018) Preview release id
#define MAX_RELEASE_R20_PREVIEW     19900
//! 3ds Max R20 (2018) release id
#define MAX_RELEASE_R20     20000
//! 3ds Max R21 (2019) Preview release id
#define MAX_RELEASE_R21_PREVIEW     20900
//! 3ds Max R21 (2019) Preview 2 (ShapeObject revisions)
#define MAX_RELEASE_R21_PREVIEW2    20901
//! 3ds Max R21 (2019) release id
#define MAX_RELEASE_R21     21000
//! 3ds Max R22 (2020) Preview release id
#define MAX_RELEASE_R22_PREVIEW     21900
//! 3ds Max R22 (2020) release id
#define MAX_RELEASE_R22             22000

Now , My question is How can I reverse the result value [a number] to get those flags? Is any way to do it?


Solution

  • In the form of macros the inverse transforms are:

    #define MAX_SDK_REV_V (VERSION_3DSMAX & 0xFF)
    #define MAX_API_NUM_V ((VERSION_3DSMAX >> 8) & 0xFF)
    #define MAX_RELEASE_V ((VERSION_3DSMAX >> 16) & 0xFFFF)
    

    You can easily convert them into functions.

    Demo