What is the best way to construct a bit mask in C with m set bits preceded by k unset bits, and followed by n unset bits:
m
k
n
So, you are asking for m set bits prefixed by k reset bits and followed by n reset bits? We can ignore k since it will largely be constrained by the choice of integer type.
mask = ((1 << m) - 1) << n;