Isn't it better to generate a mask by a preprocessor macro when the shift value and data length are #define like OP?
#define