Skip to content

Bit Manipulation

Computers store numbers as rows of 0s and 1s. Working directly on those bits (AND, OR, XOR, shifts) gives tricks that are fast and use no extra memory — such as XOR cancelling pairs of equal numbers.

After this topic: You can read and write the XOR, AND, shift and mask idioms and explain why each one works.

Do these first: 1-D Dynamic Programming

0 of 7 solved0%

Step 1 · Read the lesson

Bit Manipulation & Math

XOR tricks, bit counting, in-place matrix moves, fast exponentiation and digit-by-digit arithmetic.

Step 2 · Solve the problems in order

Try each one for about 20 minutes first. Problems with a Run code tab are checked right here. If you are stuck, open Nudge, think again, then Idea. Go skeleton only gives the function shape, and Reference solution is for comparing after you have tried. Tick the box when you could solve it again without help.

  1. 1.Single NumberEasy
  2. 2.Number of 1 BitsEasy
  3. 3.Counting BitsEasy
  4. 4.Reverse BitsEasy
  5. 5.Missing NumberEasy
  6. 6.Sum of Two IntegersMedium
  7. 7.Reverse IntegerMedium

Step 3 · What this unlocks