For computation, this will not give you advantages, because today processors are optimized for 32-bit or 64-bit arithmetic.
If you need them for size problems, it might make sense to define your own container of n-bit numbers, and it can be easily encoded.
Even more general may be a container for mod-n numbers (i.e. for numbers from 0 to n-1, not necessarily modulo with an exact power of two). For this, a simple solution (but not optimal in space) could be based on the greatest power n, which corresponds to a 64-bit integer (for example, you can pack 22 numbers between 0 and 6 into one number from 0 to 2 ** 64 -1 )
source share