Just use the OR and AND operations. To perform this operation:
start byte: 0000 0001
clear bit 1: 0000 0001 and 1111 1110 → the result is 0000 0000 (1 bit of the second operand must be 0 to clear the bit)
now set bit 2: 0000 0000 | 0000 0010 → the result is 0000 0010 (the 2nd bit of the second operand must be 1 to set the bit)
, , .
, , :
n - 2 ^ n
n - 1111 1111 XOR 2 ^ n ( 1111 1111 XOR).