What you will learn

How binary representation and two's complement encode every signed 32-bit integer

The six bitwise operators (AND, OR, XOR, NOT, left shift, right shift) and what each does at the bit level

The kth bit pattern in all four of its forms: check, set, unset, and toggle

The full XOR family: cancellation, swapping, toggle counting, and odd-occurrence detection

Bitmasking as a way to enumerate every subset of N elements in O(N * 2^N) time

Where the bit view beats arithmetic: parity, powers of two, and fast exponentiation in O(log N)

Why this course

Most engineers treat bit manipulation as a bag of memorised tricks. n & (n - 1) clears the lowest set bit, n & -n isolates it, a ^ a cancels to zero. The recipes work until an interviewer asks you to find a missing number in O(1) space, generate every subset of an array, or count parity in constant time, and you cannot derive the move because you never understood why the trick worked in the first place.

This course rebuilds your bit-level thinking starting from binary representation and two's complement, then walks you through the six patterns that cover almost every bit manipulation question you will see in a coding interview. Across 21 problems you learn when XOR cancellation beats hashing, when a bitmask collapses a recursive enumeration into a single loop, and when the binary view turns an O(N) scan into an O(1) check.

Requirements

The course assumes you can read code in any mainstream language, but no prior bit-level experience is needed.

  • Comfort writing loops, conditionals, and functions in at least one language.
  • Familiarity with basic Big-O notation (O(1), O(N), O(log N)).
  • Willingness to think in binary instead of decimal when reading a problem.

Overview

Bit manipulation is what your CPU does on every arithmetic operation. Every integer in memory is a fixed-width sequence of bits, and every +, *, or == your code runs decomposes into bit-level operations underneath. Most of the time the abstraction is invisible. But certain problems, counting parity in a network packet, encoding a subset as a single integer, finding a duplicate without extra memory, are solved naturally at the bit level and clumsily at any higher one. This course teaches you to see those problems and answer them in their native language.

Representation of bit manipulation

The course covers both halves of the problem: the bit-level operations themselves, and the six patterns that compose them into solutions.

Fundamentals

The course opens with the binary representation of integers. You see how a positive integer maps to its base-2 digits and how negative numbers are encoded under two's complement: flip every bit, then add one. Once that picture is clear, the meaning of the sign bit, why INT_MIN is -2^31 instead of -(2^31 - 1), and why XOR detects opposite signs all follow from the same layout.

From there the course covers the six bitwise operators: AND, OR, XOR, NOT, left shift, and right shift. Each operator has a truth table and each truth table has a use. AND masks bits, OR sets bits, XOR toggles bits and cancels duplicates, left shift multiplies by powers of two, and right shift divides. The course frames every later pattern as a composition of these six primitives. You build a mask, apply the right operator, then read the result.

The fundamentals close with the kth bit pattern, where the four core moves of bit manipulation appear together for the first time. Building a mask with 1 << (k - 1), you check a bit with AND, set it with OR, unset it with AND-NOT, and toggle it with XOR. Every later pattern in the course composes these four moves on a larger scale.

Problem solving

After the fundamentals, the rest of the course is patterns. Most bit manipulation problems you will see in an interview reduce to one of six templates. Once you can see the bit-level structure of the problem, the solution writes itself.

The 6 bit manipulation patterns you'll master
Kth bit
Build a mask with 1 << (k - 1) then AND, OR, XOR, or AND-NOT to check, set, toggle, or unset the kth bit in O(1) time. Kth Bit Check, Set Kth Bit, Unset Kth Bit, Toggle Kth Bit.
Set bit finder
Use n & -n to isolate the rightmost set bit and a log to convert it to a position, locating set bits in O(1) time without a loop. Only Set Bit, Rightmost Set Bit.
Restructuring
Walk an integer bit by bit to reverse, rotate, or rearrange its bit layout in O(1) time on a fixed-width 32-bit type. Reverse Bits, Circular Shift Bits.
XOR
Use the cancellation property (a ^ a = 0, a ^ 0 = a) to swap, toggle, and isolate elements that appear an odd number of times in O(N) time and O(1) space. Have Opposite Signs, Swap Numbers, Toggle Count, Odd Occurring Element, Odd Occurring Element II, Duplicate Element, Missing And Duplicated Elements.
Bitmasking
Treat each bit of an integer as a flag for one element, then enumerate 2^N masks to generate every subset of an N-element collection in O(N · 2^N) time. Pairwise Bits Swap, Unique Subsets.
Applications
Apply the bit view to classic numeric problems where the binary representation collapses an O(N) loop into an O(log N) or O(1) branch. Parity Checker, Power of 2, Parity Checker II, Power Function.

Each pattern starts with the simplest problem in the family and ramps up. The XOR pattern opens with Have Opposite Signs and Swap Numbers so you internalise the cancellation property on numeric input, then extends to Odd Occurring Element and finally Missing and Duplicated Elements where the same reasoning runs across arrays. The course closes with the Applications pattern, where parity, powers of two, and fast exponentiation show the bit view turning naive arithmetic into solutions you can derive on a whiteboard without notes.

How this course is different

Most bit manipulation material on the internet teaches the tricks without the reasoning. This course refuses to do that.

Most DSA resources
This course
Treat bit manipulation as a list of one-line tricks to memorise rather than a system to learn.
Opens with binary representation and two's complement so every later trick has a derivation behind it.
Show you n & (n - 1) without explaining why the cancellation works on any number.
Builds every pattern from the same six bitwise operators, making mask construction reusable across problems.
Skip binary representation and two's complement, so the sign-bit tricks stay magical.
Treats the XOR family as four distinct uses of one cancellation property: opposite-sign detection, swapping, toggle counting, and odd-occurrence isolation.
Cover XOR as if it were one trick instead of a family with cancellation, swapping, and odd-occurrence variants.
Connects bitmasking back to the kth bit mask, so subset enumeration in O(N · 2^N) feels obvious instead of clever.
File bitmasking under "advanced topics" and never connect it to the kth bit mask construction.
Closes with applications (parity, powers of two, fast exponentiation) where the bit view beats arithmetic on real numeric problems.

Who this course is for

The course suits anyone who needs to understand bit manipulation rather than just memorise its tricks.

  • New programmers who can write loops and conditionals but have never thought about what happens to bits when they compute a + b.
  • Self-taught and bootcamp graduates who solve array problems comfortably but freeze when a question says "do this in O(1) space" or "without using a loop".
  • Working developers who use bitwise operators in flag fields, feature toggles, or network code but cannot derive n & (n - 1) from first principles.
  • Engineers preparing for FAANG and Big Tech interviews where bit manipulation appears in systems, embedded, and senior-level coding rounds.
  • Returning engineers who learned binary years ago in a college course and want a refresher anchored in interview-grade problems.
  • Anyone who has seen ^, &, and << in code review and would rather understand them than skim past them.

Continue your DSA journey

Bit manipulation pairs naturally with several other topics in this curriculum. After this course, the natural next steps depend on where you want to deepen.

  • Array: Bitmasking enumeration runs over arrays, and many XOR problems take arrays as input. The array course teaches the underlying patterns (two pointers, sliding window) that combine with bit tricks in the harder mixed problems.
  • Hash table: For counting and odd-occurrence problems, hash tables are the alternative to XOR. This course shows when each one wins. XOR gives you O(1) extra space when elements pair up cleanly, hash tables handle the general case. Knowing both makes the choice in an interview instant.
  • Recursion: Fast exponentiation, computing num^n in O(log N) by splitting n along its bits, is the canonical place where bit manipulation meets recursion. The recursion course gives you the call-stack picture that makes the divide-and-conquer over bits feel natural.
  • Backtracking: Subset and permutation generation can be done with backtracking recursion or with bitmask iteration. The two approaches solve the same problems with different tradeoffs in space and clarity, and seeing both makes you faster at picking the right one.
  • Dynamic programming: Bitmask DP is one of the major DP genres, covering travelling salesman, set cover, and assignment problems. It depends entirely on the bitmask construction taught in this course, which DP material usually assumes you already know.

Frequently asked questions

Code examples use Python for readability, but every concept (binary representation, two's complement, bitwise operators) is language-agnostic. The course explicitly notes where languages differ, for example how C and Java treat right shift on signed integers compared to Python's arbitrary-precision integers.
Yes. The course starts from how a single integer is stored as bits in memory and builds up from there. If you can write a for loop in any language and read Big-O notation like O(N), you have everything you need to follow along.
There are 6 patterns and 21 problems. Most learners finish the conceptual lessons in 6 to 10 hours and need another 10 to 15 hours to work through the problems, depending on prior comfort with binary arithmetic.
Bit manipulation appears regularly in FAANG coding rounds, especially in systems, embedded, and infrastructure teams where memory and constant-factor cost matter. The XOR, bitmasking, and applications patterns covered here account for almost every bit manipulation question you will see.
LeetCode shows you problems one at a time without grouping. This course teaches the six patterns first and the binary representation underneath them, then drills problems within each pattern. You build pattern recognition and a derivation habit instead of memorising 30 individual one-liners.
XOR has two properties that combine into the trick. First, a ^ a = 0: any number XORed with itself cancels to zero. Second, XOR is commutative and associative, so the order of the operations does not matter. If you XOR every element of the array together, every number that appears an even number of times pairs up and cancels, leaving only the odd-occurring number. The whole solution runs in O(N) time and O(1) space.
Two's complement is how nearly every modern CPU encodes signed integers. To get the negative of a number, you flip every bit and add one. The reason this scheme is universal is that addition, subtraction, and the bitwise operators all work uniformly across signed and unsigned values without a separate sign-handling step. It matters for bit manipulation because the sign bit is just bit 31 of a 32-bit integer, which is why XORing two numbers and looking at the result's sign bit tells you whether they have opposite signs in O(1).
Yes. Once you finish all the lessons and problems, codeintuition issues a shareable certificate you can post to LinkedIn or attach to a job application.