keep last n bits 1

keep last n bits

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

Here is what the above code is Doing:
1. Create a mask that has the first n bits set to 1.
2. Use the mask to extract the last n bits of the value.

Similar Posts