This one tripped me up a bit. I had to cast -1 to an unsigned because otherwise the compiler did an arithmetic shift. This was also the case for ~0. The first shift (>> 32 - len) creates a mask of 1s on the RHS that is of length len, and the second shift (<< pos) moved the mask to start at pos.