Skip to content

Bit Manipulation

46 Posts

Introduction to 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.

Solution Review: Power of 2

Solution review for the Power of 2 challenge: solve it using Brian Kernighan's algorithm, optimized to O(1) time and space, with a step-by-step explanation.

Solution Review: Check If a Given Number is Even/Odd

This is a solution to another Bitwise question. Think of the rightmost bit of a number and think of some logic that could solve this. We solve using AND operator with O(1) time Complexity.

Solution Review: Count Set Bits Or Number of 1 bit's

We saw an algorithm to solve this problem in the previous lesson. Let’s see how to solve this more efficiently using Briann’s Algorithm. This is a faster execution than the previous naive approach.

Bitwise OR, Computations, and Examples

Learn the bitwise OR operation: how it takes two bit patterns of equal length and performs a logical inclusive OR on each pair, with worked computations.

Number Of Flips Required To Make a|b Equal to c

We need to write a program with minimum flips to make the two bits’ OR operation equal a number. If you understand the OR operations clearly, this problem will be a good challenge for your skills.

Introduction to NOT Operator

Learn the bitwise NOT operator: how it flips each bit in the binary representation of a single input, with clear examples of what it does to a value.

Bitwise NOT, Computations, and Examples

Bitwise NOT, takes the input number, considers its binary representation, and inverts every bit, which means the 0 bit becomes 1, and the 1 bit becomes 0.

Introduction to OR Operator

Learn the bitwise OR operator: how it compares each bit of two operands and when the result is 0 or 1, with clear examples of the computation in binary.

Challenge 3: Power of 2

We solve by making use of the & operator in computers. There are many ways to solve this, of which two approaches are simple, and one is a more complex but better solution.