uint32_t extract first bits

unsigned  mask;
mask = (1 << X) - 1;
lastXbits = value & mask;