where n is the bit number, and 0 is the least significant bit
Example:
Example:
assuming 16 bit, 2-byte short integer:
assuming 16 bit, 2-byte short integer, two's complement:
The code below shows how to set or clear a bit of an integer.
Output is:
延伸閱讀: Bitwise Operators in C
x ^ y == (~x & y) | (x & ~y)