You can do so by using the ` operator, which inverts bits.
using your exact example, it would look like
uint32_t buffer=~(-1<<(index+1));
the code shifts -1 by the index you want, then inverts them, leaving a bitmask of however many bits you specified