Bit Manipulation
Software Engineer path · lesson 47 of 99Bit manipulation involves working directly with the binary representation of data. Master AND, OR, and XOR operations—three fundamental bitwise operations used in competitive programming, systems optimization, and low-level algorithms. Learn to solve problems like finding unique elements in linear time, testing powers of two, and implementing efficient bitmasks for sets. Essential knowledge for interview questions and real-world performance-critical code.
12 & 10: combine the bits column by column, from the right.
- 1for each bit i: r[i] = a[i] AND b[i] # 1 only if both are 1
- Bit operations
- 0 / 8
Tap any element in the diagram to inspect its state at this step.
Keys: ← → step, Space play/pause. Predict mode pauses before key steps and asks what happens next.
Which operator?
Sort each trick by the bitwise operator that replaces the ?.
Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.
AND (&)
Drop items hereOR (|)
Drop items hereXOR (^)
Drop items hereTest your knowledge
Which property of XOR allows finding a unique number in pairs?
Write the code
Single Number
function singleNumber(nums) {
// Your code here
}The short version
Think of light switches. Each bit is just a switch (ON/OFF). Bit manipulation allows you to flip specific switches or check patterns incredibly fast, far faster than doing math.
In more depth
Bitwise Power
Bit manipulation involves working directly with the binary representations of data.
Essential Tricks:
x ^ x = 0x ^ 0 = xx & 1 checks if x is odd/even.x & (x-1) clears the lowest set bit (helps count set bits).When to reach for this
- Low-level optimization
- Representing sets using bitmaps
- Finding unique numbers
- Counting set bits (Hamming Weight)
Interview Questions
References & Further Reading
Love this visualization?
Sign up to track your progress, earn achievements, use the AI assistant, and access your personal learning dashboard.
100% free • No credit card required