Assuming that you are indexing bits from the right, this should work to unset a particular bit in value
:
int mask = 1 << bitIndex;
value &= ~mask;
You can set the bit using similar code:
value |= mask;
where mask
is as before. (This assumes that bit indexing starts at 0.)