Check out example codes for "keep last n bits". It will help you in understanding the concepts better.

Code Example 1

unsigned  mask;
mask = (1 << n) - 1;
unsigned lastNbits = value & mask;

Learn ReactJs, React Native from akashmittal.com