I would like to set the i-th bit to zero no matter what the i-th bit is.
unsigned char pt = 0b01100001;
pt[0] = 0; // its not how we do this...
Setting it to one, we can use a mask pt | (1 << i)
but i'm not sure how to create a mask for setting 0, if thats possible.
You just have to replace the logical
OR
with a logicalAND
operation. You would use the&
operator for that:You have to invert your mask because logical
AND
ing with a1
will maintain the bit while0
will clear it... so you'd need to specify a0
in the location that you want to clear. Specifically, doing1 << i
will give you a mask that is000...010..000
where the1
is in the bit position that you want, and inverting this will give111...101...111
. LogicalAND
ing with this will clear the bit that you want.You could stick with this: