Given a non-negative integer n. The problem is to check if binary representation of n is palindrome or not. Note that the actual binary representation of the number is being considered for palindrome checking, no leading 0’s are being considered.
Input : 9 Output : Yes (9)10 = (1001)2 Input : 10 Output : No (10)10 = (1010)2
Approach: Following are the steps:
- Get the number obtained by reversing the bits in the binary representation of n. Refer this post. Let it be rev.
- If n == rev, then print “Yes” else “No”.
Time Complexity: O(num), where num is the number of bits in the binary representation of n.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Check if binary representation of a number is palindrome
- Python | Check if binary representation is palindrome
- Find the n-th number whose binary representation is a palindrome
- Check if binary representation of a given number and its complement are anagram
- Check if the binary representation of a number has equal number of 0s and 1s in blocks
- Check if all the set bits of the binary representation of N are at least K places away
- Binary representation of a given number
- Binary representation of next number
- Count number of trailing zeros in Binary representation of a number using Bitset
- Largest number with binary representation is m 1's and m-1 0's
- Next greater number than N with exactly one bit different in binary representation of N
- Binary representation of previous number
- Check if Inorder traversal of a Binary Tree is palindrome or not
- Number of leading zeros in binary representation of a given number
- Prime Number of Set Bits in Binary Representation | Set 1
- Occurrences of a pattern in binary representation of a number
- Find the number obtained after concatenation of binary representation of M and N
- Number of mismatching bits in the binary representation of two integers
- Find consecutive 1s of length >= n in binary representation of a number
- C program to count zeros and ones in binary representation 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