1
votes

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?

3

3 Answers

2
votes

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

0
votes

To obtain the bits n to m of a unsigned i do the following:

(i>>n)%(1 << (m-n));

(Maybe I am off by one but roughly that). You shift the number first n to the right, that removes all bytes right of the n-th. Then you have to cut off all numbers above the one you want, which is now the n-m-th and for that you need to modulo it with 2^(n-m).

0
votes
int flag = MAX_RELEASE_R18_PREVIEW; // 17900

// MAX_SDK_REV
int a = (flag & 0xff); // 236

// MAX_API_NUM
int b = (flag & 0xff00) >> 8; // 69

// MAX_RELEASE
int c = (flag & 0xff0000) >> 16; // 0