BITWISE OPERATIONS
AND
input1 & input2OR
input1 | input 2XOR
input1 ^ input2NOT
~input1BIT SHIFT LEFT
think of this as multiplying by 10. In base 2, shifting a value one bit to the left corresponds to multiplying it by 2
12345 x 10 = 12345[0]
* this shifts all digits to the left then filling the gap with a 0
variable << bits
* the left argument (bits) is an integer whose bits are shifted and determines the SIZE fo the shiftBIT SHIFT RIGHT
think of this as dividing by 10. In base 2, shifting one bit to the right corresponds to dividing by 2
12340 / 10 = 1234[]
* this shifts all digits to the right then dropping the right-most bit []
variable >> bits
* * the left argument (bits) is an integer whose bits are shifted and determines the SIZE fo the shiftDETECTING BIT STATE
if (flagRegister & mask)
puts("bit is set");
else
puts(bit is not set");RESETTING BIT
flagRegister &= ~mask;
* 1111111111111111111111111111110111SETTING BIT
flagRegister = flagResiter | mask;
x | 1 = 1
x | 0 = xNEGATING BIT
FlagRegister = FlagRegister ^ TheMask;
x ^ 1 = !x
x ^ 0 = xLast updated