Just fill the non mask bits with ones so that they propagate carry:
// increments x on bits belonging to mask
x = ((x | ~mask) + 1) & mask;
Just fill the non mask bits with ones so that they propagate carry:
// increments x on bits belonging to mask
x = ((x | ~mask) + 1) & mask;