First, create a number with N-th bit set and all other bits clear. This value is
1 << N
.
On next step, take your original value and calculate the bitwise OR with the value from the previous step.
That is:
int N = int value = value |= 1 << N; value = value | (1 << N)
To clear a bit, use bitwise AND with the complement:
value &= ~(1 << N);
That's all. Learn the bitwise operators:
http://www.learncpp.com/cpp-tutorial/38-bitwise-operators[
^].
—SA