SYSTEMS / Learn
Saved on this device>
← Back to curriculum

Learning-oriented

Think one bit at a time

Build intuition for AND, OR, and XOR.

1 · Understand → 2 · Explain from memory → 3 · Practise → 4 · Spaced review

Bitwise operators work independently at each position. AND produces 1 only when both input bits are 1. OR produces 1 when at least one input bit is 1. XOR produces 1 exactly when the inputs differ.

Align the operands by their least significant bit, then work column by column. No carry crosses between columns. This is why bitwise AND is different from multiplication, even when some small examples look similar.

Useful identities: x & x = x, x | 0 = x, and x ^ x = 0. XOR is reversible: (x ^ mask) ^ mask = x. Try each identity in the bit lab.

Explain it before you practise

Look away from the example. Explain why it works and predict a boundary case. Then check your reasoning.

Why does XOR with the same mask twice restore the original word? Would OR do the same?

Check your reasoning

Each 1 in the mask flips a bit twice, restoring it; each 0 leaves it alone. OR only sets bits and loses their previous values, so applying it again cannot undo the change.

Cement this knowledge

Solve ten fresh questions without the worked example. Mistakes return during the session; spaced review helps you recall the method on later days.

Practice this topic →
coffee-bytes / Systems LearningCS:APP + Hacker’s Delight