Skip to content

Grokking Bit Manipulation For Coding Interviews

Bit Manipulation is a powerful technique that solves bit-related problems mostly in constant time.

Gopi Gorantala
Gopi Gorantala
4 min read

Table of Contents

Course Overview

In this course, you will learn how to solve problems using bit manipulation, a powerful technique that can be used to optimize your algorithmic and problem-solving skills.

This is one of the most important/critical topics when someone starts preparing for coding interviews for FAANG companies.

To kick things off, you’ll start by learning about the number system and how it’s represented. Then you’ll learn about the six bitwise operators: AND, OR, NOT, XOR, and bit shifting. Throughout, you will get tons of hands-on experience working through practice problems to help sharpen your understanding. By completing this course, you can solve problems faster and more efficiently.

What Do You Get?

🧸 45 lessons were categorized based on topics.

🧸 28 challenges.

🧸 30+ Illustrations and sketches

🧸 271 solutions provided.

🧸 Solutions are written in Java, Python, JavaScript, C++, and TypeScript.

🧸 GitHub repository access - Java, JavaScript

Takeaway Skills

  1. Master problem-solving that involves bit manipulation.
  2. Master the bit manipulation allows you to organize all inputs in binary representation at the memory levels. 
  3. Master how the bit-level operations are computed. Understand that bit-level operations are based on all the arithmetic operations built into all languages.
  4. Solve problems that are commonly asked in coding interviews related to bit manipulation.
  5. These bit tricks could help in competitive programming in running algorithms, mostly in O(1) time.

Estimated Time: 8hrs to complete.

Getting Started

Introductory learning topics about bit-manipulation. Start here to learn the basics.

  1. Introduction to bit manipulation (preview)
  2. What is bit manipulation? (preview)


  1. Grab your FREE IntelliJ Idea/JetBrains license 🤩

Number Systems, Bitwise, and Binary

Next, you need to understand the number systems in mathematics like binary, decimal, octal, and hexadecimal. You will be introduced to number representations and mathematical conversions.

  1. Introduction to number systems (preview)
  2. Decimal number system (preview)
  3. Binary number system and representation (preview)
  4. What are bitwise operators? (preview)
  5. Count the number of digits in an integer (preview)
  6. Convert Decimal Numbers to binary numbers (preview)

Bitwise AND

The Bitwise AND operator is denoted by &. When an AND gate is given with 2 inputs, the corresponding outputs will be: If two input bits are 1, then the output is 1. In all other cases, it is 0.

  1. Introduction to AND operator
  2. Bitwise AND, computations, and examples
  3. Challenge 1: Count set bits or number of 1 bit's (preview)
  4. Solution Review: Count set bits or number of 1 bit's (preview)
  5. Counting bits II
  6. Challenge 2: Check if a given number is even/odd
  7. Solution Review: Check if a given number is even/odd
  8. Challenge 3: Power of 2 (preview)
  9. Solution Review: Power of 2 (preview)

Bitwise OR

The Bitwise OR operator is denoted by |. When an OR gate is given with 2 inputs, the corresponding outputs will be: If two input bits are 0, then the output is 0. In all other cases, it is 1.

  1. Introduction to OR operator
  2. Bitwise OR, computations, and examples
  3. Number of flips required to make a|b equals c

Bitwise NOT

The Bitwise NOT operator evaluates the binary representation of the value of a single input. If the bit contains 1, the output will be 0 for that bit location. If the bit contains 0, the output will be 1.

  1. Introduction to NOT operator
  2. Bitwise NOT, computations, and examples
  3. Switch sign of a number

Bitwise XOR

The Bitwise XOR operator is denoted by ^. When an XOR gate is given with 2 inputs, the corresponding outputs will be: If two input bits are different, the output is 1. In all other cases, it is 0.

  1. Introduction to XOR
  2. Bitwise XOR, computations, and examples
  3. Swap two numbers
  4. Find odd occurring element
  5. Detect if two integers have opposite signs
  6. Hamming distance
  7. Challenge 1: Single number
  8. Solution Review: Single number
  9. Challenge 2: Missing number
  10. Solution Review: Missing number

Bit Shifring - Left, Right

A bit shift is a Bitwise operation where the order of a series of bits is moved, either to the left or right, to efficiently perform a mathematical operation.

  1. Introduction to bit shifting
  2. Left shifts
  3. Arithmetic and logical right shifts
Bitwise Left Shift Problems

Problems on left shift.

  1. Find the bit length of a number
  2. Check if the kth bit is set/unset using left shift
  3. Subsets or Powerset (preview)
  4. Challenge 1: Get the first set bit position using the left shift
  5. Solution Review: Get the first set bit position using the left shift

Bitwise Right Shift Problems

Problems on the right shift.

  1. Check if the kth bit is set/unset using right shift
  2. Challenge 1: Get the first set bit position using the right shift
  3. Solution Review: Get the first set bit position using the right shift

Final Thoughts

This concludes the course on bit manipulation.

This course has taught you how to re-write arithmetic operators like +, -, /, * into left, right shift, and other bit-level operations.

I hope the learning you gained in this course will be useful in solving Leetcode, Hackerrank, HackerEarth, Codeforces, Codechef, and other online coding challenges. This will also help you with interviews at FAANG or other top tech companies.

I wish you good luck and hope this course makes a difference in your coding journey!

Note: In the upcoming edits, you will see the following items:

  1. Solutions in Rust and Go.
  2. A few medium and hard problems were asked in recent FAANG and fast-paced startup coding interviews.

Happy Coding 👨🏻‍💻 !!

If you have finished the course, I'm super happy for you 🥳, and it's been a pleasure to be part of your professional journey.

I'm working hard in my spare time to keep the site up and running and to update the site with the most requested features. So long as people are having fun, I want to keep the site going.

Gopi Gorantala Twitter

Gopi is a highly experienced Full Stack developer with a deep understanding of Java, Microservices, and React. He worked in India & Europe for startups, the EU government, and tech giants.


Related Posts

Members Public

SOLID Design Principles

SOLID are not "design patterns", but design principles for effective object-oriented design while designing a class structure.

Members Public

Functional Programming With Lambdas & Streams API

Java 8 is bundled with massive features and improvements to the JDK, JRE and more. It introduced functional programming in Java.

Members Public

Mastering Data Structures and Algorithms For Coding Interviews

Getting Started 1. Who Is This Course For? 2. How Can This Improve My Coding Skills? Introduction To Data Structures and Algorithms 3. What Are Data Structures And Algorithms? 4. What is Big O Notation 5. Complexity Analysis 6. Time and Space Complexity Arrays 7. Introduction To Array Data Structure