You just have to replace the logical OR
with a logical AND
operation. You would use the &
operator for that:
pt = pt & ~(1 << i);
You have to invert your mask because logical AND
ing with a 1
will maintain the bit while 0
will clear it... so you'd need to specify a 0
in the location that you want to clear. Specifically, doing 1 << i
will give you a mask that is 000...010..000
where the 1
is in the bit position that you want, and inverting this will give 111...101...111
. Logical AND
ing with this will clear the bit that you want.