Manipulating individual bits to perform operations.
AND The bitwise AND operation is a binary operation that takes two binary numbers and performs a logical AND operation on each pair of corresponding bits. If both bits are 1, the result is 1. If on...
Problem Statement: Given a decimal number N, remove the rightmost set bit ie. the rightmost 1 in the binary representation and return the updated number. Examples Input: N = 12 Output: 8 Explanatio...
Problem Statement: Given an array of numbers, print all subsets of it using bitwise operators. Examples Input: nums = [1, 2, 3] Output: [[ ], [1], [2], [3], [1, 2], [2, 3], [3, 1], [1, 2, 3]] Expla...
Problem Statement: Given two numbers ‘a’ and ‘b’, swap them without using a third variable. Return ‘a’ and ‘b’ with the swapped values. Examples Input: a = 20, b = 10 Output: a = 10...
Problem Statement: Given a decimal number N, return the number of set bits in its Binary representation. Examples Input: 13 Output: 3 Explanation: The decimal number N = 13 has a binary representat...
Problem Statement: Given a decimal number N and an index i, toggle the ith position of the number, i.e., if the bit at position i is 0, then change it to 1, and if it is 1, then change it to 0. Exa...
Decimal to Binary Conversion The decimal numeral system, also known as base-10, is the standard system for denoting integer and non-integer numbers. It uses ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, a...
Problem Statement: Given two integers dividend and divisor, divide two integers without using multiplication, division, and mod operator. The integer division should truncate toward zero, which mea...
Problem Statement: Given two integers L and R return the XOR of elements of the range [L, R]. . Examples Input: L = 4, R = 8 Output: 8 Explanation: The XOR of all numbers from 4 to 8 is: 4^5^6^7^8...
Problem Statement: Given an integer N, find the XOR of all numbers from 1 to N. Examples Input : N = 5 Output : 1 Explanation : The XOR of all numbers from 1 to 5 is: 1^2^3^4^5 = 1 Input : N = 10 O...