BITWISE OPERATIONS

AND

input1 & input2

OR

input1 | input 2

XOR

input1 ^ input2

NOT

~input1

BIT 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 shift

BIT SHIFT RIGHT

think of this as dividing by 10. In base 2, shifting one bit to the right corresponds to dividing by 2

DETECTING BIT STATE

RESETTING BIT

SETTING BIT

NEGATING BIT

Last updated