Question: How to set (in most elegant way) exactly `n` least significant bits of `uint32_t`? That is to write a function `void setbits(uint32_t *x, int n);`. Function should handle each `n` from `0` to `32`.

Especially value `n==32` should be handled.

Answer: 
```
const uint32_t masks[33] = {0x0, 0x1, 0x3, 0x7 ...

void setbits(uint32_t *x, int n)
{
   *x |= masks[n];
}

```
If you mean the most significant n bits:

```
-1 ^ ((1 << (32 - n)) - 1)

```