Bitwise Algorithms
Learn more about Bitwise Algorithms in DSA Self Paced Course
Practice Problems on Bit Magic !
The Bitwise Algorithms is used to perform operations at the bit-level or to manipulate bits in different ways. The bitwise operations are found to be much faster and are sometimes used to improve the efficiency of a program.
For example: To check if a number is even or odd. This can be easily done by using Bitwise-AND(&) operator. If the last bit of the operator is set than it is ODD otherwise it is EVEN. Therefore, if num & 1 not equals to zero than num is ODD otherwise it is EVEN.
Topics:
- Introduction to Bitwise Algorithms – Data Structures and Algorithms Tutorial
- Bitwise Operators in C/C++
- Bitwise Operators in Java
- Python Bitwise Operators
- JavaScript Bitwise Operators
- All about Bit Manipulation
- Little and Big Endian Mystery
Standard Problems on Bit Algorithms:
- Easy:
- Binary representation of a given number
- Count set bits in an integer
- Add two bit strings
- Turn off the rightmost set bit
- Rotate bits of a number
- Compute modulus division by a power-of-2-number
- Find the Number Occurring Odd Number of Times
- Program to find whether a no is power of two
- Find position of the only set bit
- Check for Integer Overflow
- Find XOR of two number without using XOR operator
- Check if two numbers are equal without using arithmetic and comparison operators
- Detect if two integers have opposite signs
- How to swap two numbers without using a temporary variable?
- Russian Peasant (Multiply two numbers using bitwise operators)
- Medium:
- Swap bits in a given number
- Smallest of three integers without comparison operators
- Compute the minimum or maximum of two integers without branching
- Smallest power of 2 greater than or equal to n
- Program to find parity
- Check if binary representation of a number is palindrome
- Generate n-bit Gray Codes
- Check if a given number is sparse or not
- Euclid’s Algorithm when % and / operations are costly
- Calculate square of a number without using *, / and pow()
- Cyclic Redundancy Check and Modulo-2 Division
- Copy set bits in a range
- Check if a number is Bleak
- Gray to Binary and Binary to Gray conversion
- Hard:
- Next higher number with same number of set bits
- Karatsuba algorithm for fast multiplication
- Find the maximum subarray XOR in a given array
- Find longest sequence of 1’s in binary representation with one flip
- Closest (or Next) smaller and greater numbers with same number of set bits
- Bitmasking and Dynamic Programming | Set-2 (TSP)
- Compute the parity of a number using XOR and table look-up
- XOR Encryption by Shifting Plaintext
- Count pairs in an array which have at least one digit common
- Python program to convert floating to binary
- Booth’s Multiplication Algorithm
- Number of pairs with Pandigital Concatenation
- Find the n-th number whose binary representation is a palindrome
- Find the two non-repeating elements in an array of repeating elements
- Learn Data Structure and Algorithms | DSA Tutorial
- ‘Practice Problems’ on Bit Magic
- ‘Quiz’ on Bit Magic
- ‘Videos’ on Bit Magic
If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.