Bitwise Algorithms - Basic Practice Problems
Last Updated :
23 Aug, 2024
Improve
Bitwise algorithms are a category of algorithms that operate on individual bits within a data unit, rather than the entire data unit itself. They leverage bitwise operators, which are special operators designed to perform operations on bits. Common bitwise operators include AND (&
), OR (|
), XOR (^
), and NOT (~
).
Before diving into the world of bitwise algorithms, a basic understanding of binary representation is crucial. Computers store data in binary form, where each unit (bit) can be either 0 or 1. Numbers we typically use (decimal system) are converted to binary for computer processing.
Basic Practice Problems on Bitwise Algorithm:
- Find the element that appears once
- Detect if two integers have opposite signs
- Add 1 to a given number
- Multiply a given Integer with 3.5
- Turn off the rightmost set bit
- Find whether a given number is a power of 4 or not
- Compute modulus division by a power-of-2-number
- Rotate bits of a number
- Find the Number Occurring Odd Number of Times
- Check for Integer Overflow
- Count set bits in an integer
- Count number of bits to be flipped to convert A to B
- Efficient way to multiply with 7
- Program to find whether a no is power of two
- Position of rightmost set bit
- Binary representation of a given number
- Find position of the only set bit
- How to swap two numbers without using a temporary variable?
- Swap two nibbles in a byte
- How to turn off a particular bit in a number?
- Russian Peasant (Multiply two numbers using bitwise operators)
- Add two bit strings
- Write your own strcmp that ignores cases
- Check if two numbers are equal without using arithmetic and comparison operators
- Find XOR of two number without using XOR operator
- XOR counts of 0s and 1s in binary representation
- Calculate XOR from 1 to n
- Equal Sum and XOR
- Swap three variables without using temporary variable
- Check if a number has bits in alternate pattern
- XOR of two numbers after making length of their binary representations equal
- Count minimum bits to flip such that XOR of A and B equal to C
- Efficient method for 2’s complement of a binary string
- Toggle case of a string using Bitwise operators
- Toggling k-th bit of a number
- Convert decimal fraction to binary number
- Toggle all the bits of a number except k-th bit
- Set the rightmost unset bit
- Convert a binary number to octal
- Check in binary array the number represented by a subarray is odd or even
- Toggle the last m bits
- 1 to n bit numbers with no consecutive 1s in binary representation
- Toggle bits in the given range
- Unset bits in the given range
- Find the largest number with n set and m unset bits
- Find the smallest number with n set and m unset bits
- Sum of numbers with exactly 2 bits set
- Check if binary representation of a given number and its complement are anagram
- Check a number is odd or even without modulus operator
- Bitwise recursive addition of two integers
- Print bitwise AND set of a number N
- Fast average of two numbers without division
- Maximum XOR-value of at-most k-elements from 1 to n
- Swap every two bits in bytes
- Check if a number is divisible by 8 using bitwise operators
- Number of Reflexive Relations on a Set
- For every set bit of a number toggle bits of other
- Toggle bits of a number expect first and last bits
- Check if given four integers (or sides) make rectangle
- Toggle all even bits of a number
- Toggle first and last bits of a number
- Set the Left most unset bit
- Maximum XOR using K numbers from 1 to n
- Python | Count set bits in a range
- Python map function | Count total set bits in all numbers from 1 to n
- Check whether the bit at given position is set or unset
- Multiplication with a power of 2
- Check if n is divisible by power of 2 without using arithmetic operators
- Toggle all odd bits of a number
- Count set bits using Python List comprehension
- Check if a number is positive, negative or zero using bit operators
- Modify a bit at a given position
- CHAR_BIT in C
- Find One’s Complement of an Integer
- Add two numbers without using arithmetic operators
- Multiply a number with 10 without using multiplication operator
- Check if one of the numbers is one’s complement of the other
- Check if a number has bits in alternate pattern | Set-2 O(1) Approach
- Set all the bits in given range of a number
- Calculate 7n/8 without using division and multiplication operators
- Count total bits in a number
- Find most significant set bit of a number
- Find smallest number n such that n XOR n+1 equals to given k
- Check if a number has two adjacent set bits
- Write an Efficient Method to Check if a Number is Multiple of 3
- Extract ‘k’ bits from a given position in a number
- Print ‘K’th least significant bit of a number
- Check if two numbers are equal without using comparison operators
- Efficiently check whether n is a multiple of 4 or not
- Check whether K-th bit is set or not
- Check if a number is multiple of 9 using bitwise operators
- Compare two integers without using any Comparison operator
- Multiplying a variable with a constant without using multiplication operator
- Check whether a given number is even or odd
- Powers of 2 to required sum
- Set all even bits of a number
- Set all odd bits of a number
- Print numbers having first and last bits as the only set bits
- Check if binary representations of two numbers are anagram
- Multiples of 4 (An Interesting Method)
- Given a set, find XOR of the XOR’s of all subsets.
- Write a function that returns 2 for input 1 and returns 1 for 2
- Subtract two numbers without using arithmetic operators
Quick Links :