Posts tagged

Bitwise

Bit Manipulation Tricks for Coding Interviews

A practical guide to the bitwise techniques that show up in coding interviews, starting with why interviewers love bit manipulation and a refresher on the six core operators (AND, OR, XOR, NOT, shifts). Covers six essential tricks with ASCII bit diagrams: checking and setting the k-th bit, clearing the lowest set bit with n & (n-1), XOR self-cancellation, power-of-two detection, swapping without a temp variable, and multiplying or dividing by powers of two with shifts. Then walks through five classic interview problems — single number, counting bits, missing number, power of two, and reversing bits — each with a worked Python solution and complexity analysis.