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: 
Here's a method that doesn't require any arithmetic:

```
~(~0u << n)

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

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

```