## Swap two numbers using Bitwise XOR Operator

Objective– Given two numbers, swap both the numbers using XOP operators. Example: X = 4, Y = 8 Output: X = 8, Y= 4 Approach: XOR operator There are many ways to swap two...

Objective– Given two numbers, swap both the numbers using XOP operators. Example: X = 4, Y = 8 Output: X = 8, Y= 4 Approach: XOR operator There are many ways to swap two...

Objective: Given a number n and k, Calculate n / k2 without using pow() or / operator. Example: N = 48, k = 4 N/k2 = 3 Approach: Bit Manipulation Right shift the number...

What is Left Shift (<<) Operator: a<<b means left shift the bits of number a by b places. 3<<2 means left shift the bits of number 3 by 2 places. Result = 12 011...

Objective: Given a number convert it to base 3 representation. Example: N = 35 Base 3 representation: 1022 N = 50 Base 3 representation: 1212 Approach: Till the number is greater than 0, keep...

Objective: Given an array of integers which has all the repeating numbers (twice) but two numbers which are non-repeating. Write an algorithm to find out those two numbers. Example int [] arrA = {4,5,4,5,3,2,9,3,9,8}; Output:...

Objective: Given two numbers x and y. write an algorithm to find the number of bits which are to be flipped to convert number x to y. Example x = 10, Y = 20 x...

Objective: Given an array of integers in which all the elements are appear thrice but one which appears only one. Write an algorithm to find that element. Example int [] arrA = {6,5,3,2,4,2,5,6,3,3,6,5,2}; Output: 4...

Objective: Given an array of integers, all the elements are appear twice but one element which appears only once. Write an algorithm to find that element. Example: int [] a = { 1,5,6,2,1,6,4,3,2,5,3}; output:...

Objective: Write an algorithm to count the number of 1’s in the bit representation in given number. Example: Number: 6 Output: 2 ( 1 1 0) Number: 11 Output: 3 ( 1 0 1 1)...

Objective: Given a number, write and algorithm to find the right most unset bit or zero bit in it (In binary representation). This problem is similar to: Find the right most set bit of...

Objective: Given an array of n+2 elements. All elements of the array are in range 1 to n and all elements occur once except two numbers which occur twice. Write an algorithm to find...

Objective: Given a number, write and algorithm to find the right most set bit in it (In binary representation). Example: Number : 1 Binary representation: 1 Position of right most set bit: 1 Number...

Objective: Given a array of integers, in which every elements occurs even number of times except one number which occurs add number of times. Find out that number. Example: int[] A = {...

Input: Array, arrA[] with a missing number and Range Output : missing number Example: int A[] = { 1, 2, 7, 6, 3, 4 }; int range = 7; Output: MIssing No is :5 In...

Objective: – Generate All Strings of n bits, consider A[0..n-1] is an array of size n. Example : n = 3 Output: [0, 0, 0] [1, 0, 0] [0, 1, 0] [1, 1, 0]...