You're missing the `~` which flips all the bits in the field, leaving the higher bits as `0` and the last 3 bits as `1`.  You're right that the mask won't remove the bits that are less significant than the field we're trying to access, but the `>>>` at the end will drop anything less significant than the value.

For example, I have a field with shift=2 and numBits=3: `000X XX00`.  the mask for this will be `0001 1111` which will zero out the 3 most-significant bits, making `000X XX??`.  Then finally, the value is shifted to the right by 2, making `0000 0XXX`, which is the correct value to return.