How to set a single bit?

Special K

Diamond Member
Jun 18, 2000
7,098
0
76
Let's suppose I have the bit string 00110011 and I want to clear the 5th bit. I could do:

00110011 &= 11101111 which will clear the 5th bit while preserving the rest. How do I do the opposite, ie. set a bit while preserving the rest? I'm sure the answer is simple but I'm just not thinking of it right now.

thanks
 

Special K

Diamond Member
Jun 18, 2000
7,098
0
76
OK, n/m it looks like all I have to do is OR it, and use a 0 to preserve values and a 1 to set them.