Skip to content

Category Archives: Bit Magic

Given a number n and a value k. From the right, set the kth bit in the binary representation of n. The position of LSB(or… Read More
Given two positive integers x and y, check if one integer is obtained by rotating bits of other.  Input constraint: 0 < x, y <… Read More
Given an array of integers, we need to get total XOR of all subarray XORs where subarray XOR can be obtained by XORing all elements… Read More
In competitive programming or in general some problems seems difficult but can be solved very easily with little bit magic. We have discussed some tricks… Read More
Given a positive integer n, print the next smallest and the previous largest number that has the same number of 1 bit in their binary… Read More
Given a positive (or unsigned) integer n, write a function to toggle all the bits except k-th bit. Here value of k starts from 0… Read More
Given a string, write a function that returns toggle case of a string using the bitwise operators in place.In ASCII codes, character ‘A’ is integer… Read More
Given a string, write a function that converts it either from lower to upper case or from upper to lower case using the bitwise operators… Read More
Given a string, determine if the string has all unique characters. Examples :   Input : abcd10jk Output : true Input : hutg9mnd!nk9 Output : false… Read More
Given an array, the task is to reverse the array without using subtract sign ‘-‘ anywhere in your code. It is not tough to reverse… Read More
Given a integer ‘x’, find the number of values of ‘a’ satisfying the following conditions:  0 <= a <= x a XOR x = a… Read More
We are given two numbers n and m, and two-bit positions, i and j. Insert bits of m into n starting from j to i.… Read More
Given a range [L, R], we need to find two integers in this range such that their XOR is maximum among all possible choices of… Read More
Given an array ‘arr1’ of n positive integers. Contents of arr1[] are copied to another array ‘arr2’, but numbers are shuffled and one element is… Read More
Given a non-negative integer N, the task is to find count of non-negative integers less than or equal to N whose bitwise OR and sum with… Read More

Start Your Coding Journey Now!