I have a number that is representing a mask and I want to get the negative mask (0110, that is 6). I thought to do the bitwise not but it seems that it negate also the sign bit, and I get an unwanted value...
size_t msk = 9; // that is 1001, or 000...01001 on more bits
size_t nMsk = ~msk; // this I want to be 6, that is 0110, but bitwise not
// is negating all the bits, so I get 111...10110
Is there a fast way to do it (without a loop)?
EDIT More info:
I have added some better case in some comment of one of the answer: In my case, 16 is 100000000 and ~16 is not 111011111111, but 000011111111