Given two integer numbers, whenever the bits of the first number is set i.e. 1, toggle the bits of the second number leaving the rest bits of the second number unchanged.
Input: 2 5 Output: 7 2 is represented as 10 in binary and 5 is represented as 101. Hence toggling the 2nd bit of 5 from right, thus the new number becomes 7 i.e. 111 Input: 1 3 Output: 2
Just do XOR of the given two Number.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Toggle bits of a number except first and last bits
- Toggle all the bits of a number except k-th bit.
- Toggle first and last bits of a number
- Toggle all odd bits of a number
- Toggle all even bits of a number
- Toggle the last m bits
- Toggle bits in the given range
- Toggle all bits after most significant bit
- Check if bits of a number has count of consecutive set bits in increasing order
- Set, Clear and Toggle a given bit of a number in C
- Program to toggle K-th bit of a number N
- Maximize a given unsigned number number by swapping bits at it's extreme positions.
- Find the largest number smaller than integer N with maximum number of set bits
- Check if a number has same number of set and unset bits
- Set all odd bits of a number
- Set all even bits of a number
- Same Number Of Set Bits As N
- Change all even bits in a number to 0
- Largest number less than X having at most K set bits
- Set all the bits in given range of a number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Mithun Kumar