AND, OR, XOR & Shifts
& keeping bits set in both, | keeping bits set in either, ^ keeping bits that differ, ~ flipping every bit, and << and >> shifting the bits left or right.In short: an integer is a row of bits, and four operators act on the whole row at
once: & keeps a bit only where both sides have it, | keeps a bit where either side
has it, ^ keeps a bit where the sides differ, and ~ flips every bit. << and >>
slide the whole row left or right, which multiplies or floor-divides by a power of two.
Python ints have no fixed width, so any trick that depends on a register's bits running
out (wraparound, overflow) needs an explicit mask.

Meet Quarry
For six sections you built Tunebox, a music app. From here the course builds something harder: Quarry, a search-and-storage engine. Think of the part of a database that nobody sees. It takes records in, stores them compactly, finds them again quickly and keeps them safe as they change. Over the coming sections Quarry gets a record encoder, a hash kernel, range analytics, a query planner, a text index and a diff engine. Each one is a real subsystem of a real engine, and each needs an algorithm you haven't met yet.
It starts at the bottom, with the record header. Every record Quarry stores carries four small facts: its id, the shard it lives on, its type, and the epoch (a version counter) it was written in. Held as a Python dict, that costs about two hundred bytes per record. Packed into a single 32-bit word, it costs four:
Across a hundred million records that is the difference between 20 GB and 400 MB. The
line that builds word uses two operators this lesson is about: << and |. By the
end of the section you'll have written the whole encoder yourself. You'll pack and
unpack the fields, check them, and index them with bitsets.