# Category: Bit Manipulation

## Number of bit to be flipped to convert one number to another.

Objec­tive:  Given two num­bers x and y. write an algo­rithm to find the num­ber of bits which are to be flipped to con­vert num­ber x to y. Exam­ple x = 10, Y = 20 x =…

## All elements appears thrice and one element appears once. Find that element in O(n) time and O(1) space

Objec­tive:  Given an array of inte­gers in which all the ele­ments are appear thrice but one which appears only one. Write an algo­rithm to find that ele­ment. Exam­ple int [] arrA = {6,5,3,2,4,2,5,6,3,3,6,5,2}; Out­put: 4…

## Find the only element in array which appears only once

Objec­tive: Given an array of inte­gers, all the ele­ments are appear twice but one ele­ment which appears only once. Write an algo­rithm to find that ele­ment. Exam­ple: int [] a = { 1,5,6,2,1,6,4,3,2,5,3}; output:…

## Number of 1’s in bit representation of a number

Objec­tive:  Write an algo­rithm to count the num­ber of 1’s in the bit rep­re­sen­ta­tion in given num­ber. Exam­ple: Num­ber: 6 Out­put: 2 ( 1 1 0) Num­ber: 11 Out­put: 3 ( 1 0 1 1)…

## OR zero bit of a number">Find the right most unset bit OR zero bit of a number

Objec­tive: Given a num­ber, write and algo­rithm to find the right most unset bit or zero bit in it (In binary rep­re­sen­ta­tion). This prob­lem is sim­i­lar to: Find the right most set bit of…

## Find the two repeating elements in a given array | 6 Approaches

Objec­tive: Given an array of n+2 ele­ments. All ele­ments of the array are in range 1 to n and all ele­ments occur once except two num­bers which occur twice. Write an algo­rithm to find…

## Find the right most set bit of a number

Objec­tive: Given a num­ber, write and algo­rithm  to find the right most set bit in it (In binary rep­re­sen­ta­tion). Exam­ple: Num­ber : 1 Binary rep­re­sen­ta­tion: 1 Posi­tion of right most set bit: 1 Number…

## Find a Number occurring odd number of times in a Given array

Objec­tive: Given a array of inte­gers, in which every ele­ments occurs even num­ber of times except one num­ber which occurs add num­ber of times. Find out that num­ber. Exam­ple:   int[] A = {…

## XOR Method">Find a Missing Number From a Sequence of Consecutive Numbers | XOR Method

Input:  Array, arrA[] with a miss­ing num­ber and Range Out­put : miss­ing num­ber Exam­ple: int A[] = { 1, 2, 7, 6, 3, 4 }; int range = 7; Out­put: MIss­ing No is :5 In…

## Generate All Strings of n bits.

Objec­tive: — Gen­er­ate All Strings of n bits, con­sider A[0..n-1] is an array of size n. Exam­ple : n = 3 Out­put: [0, 0, 0]    [1, 0, 0]    [0, 1, 0]    [1, 1, 0] [0,…

## Find The Missing Duplicate in a Given Array.

Objec­tive: — Given an Inte­ger array. Array con­tains dupli­cates of all the num­bers in array except one num­ber . Find that num­ber. Exam­ple : int [] A = { 2,1,3,5,5,3,2,1,6,7,7,8,8}; Out­put : Miss­ing duplicate…

## Reverse the binary representation of a number.

Objec­tive: Write a pro­gram to Reverse the binary rep­re­sen­ta­tion of a num­ber Exam­ple: Input : 30 Out­put : 15 Expla­na­tion: binary rep­re­sen­ta­tion of 30 is : 11110 reverse of binary rep­re­sen­ta­tion : 01111 decimal…