Given a number N, the task is to perform the bitwise operations on digits of the given number N. The bitwise operations include:
- Finding the XOR of all digits of the given number N
- Finding the OR of all digits of the given number N
- Finding the AND of all digits of the given number N
Input: N = 486 Output: XOR = 10 OR = 14 AND = 0 Input: N = 123456 Output: XOR = 10 OR = 14 AND = 0
- Get the number
- Find the digits of the number and store it in an array for computation purpose.
- Now perform the various bitwise operations (XOR, OR, and AND) on this array one by one.
Below is the implementation of the above approach:
XOR = 7 OR = 7 AND = 0
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.
- Leftover element after performing alternate Bitwise OR and Bitwise XOR operations on adjacent pairs
- Min number of operations to reduce N to 0 by subtracting any digits from N
- Bitwise operations on Subarrays of size K
- Minimum Bitwise OR operations to make any two array elements equal
- Minimum Bitwise XOR operations to make any two array elements equal
- Minimum Bitwise AND operations to make any two array elements equal
- Find smallest number with given number of digits and sum of digits under given constraints
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Total pairs in an array such that the bitwise AND, bitwise OR and bitwise XOR of LSB is 1
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
- Maximize the given number by replacing a segment of digits with the alternate digits given
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Number formed by deleting digits such that sum of the digits becomes even and the number odd
- Find the Largest number with given number of digits and sum of digits
- Find the average of k digits from the beginning and l digits from the end of the given number
- Check if the sum of digits of number is divisible by all of its digits
- Sum of the digits of square of the given number which has only 1's as its digits
- Number of digits in the nth number made of given four digits
- Bitwise OR( | ) of all even number from 1 to N
- Bitwise AND of all even number up to N
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.