Skip to content

Bit Manipulation

Members Public

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.

Members Public

Solution Review: Power of 2

Let's solve this using brain kernighan's algorithm. This is optimized to O(1) time and space.

Members Public

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.

Members Public

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.

Members Public

Bitwise OR, Computations, and Examples

A Bitwise OR is a binary operator that takes two-bit patterns of equal length and performs the logical inclusive OR operation on each corresponding bits pair. The result in each position is 0 if both bits are 0. Otherwise, the result is 1.

Members Public

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.

Members Public

Introduction to NOT Operator

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.

Members Public

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.

Members Public

Introduction to OR Operator

OR operator compares each bit of the first operand to the second operand’s corresponding bit. If both bits are 0, the corresponding result bit is set to 0. Otherwise, the corresponding result bit is set to 1

Members Public

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.