That's not the mask I wanted.
I think you will find that a generic approach is not as optimal as having a series of specific approaches (one for 10-bits, one for 12-bits, etc.) that you can link in for your specific applications.
If those numbers came from an adc module, many allow left-aligned adcs making the shift approach a lot more appealing.