VOOZH about

URL: https://www.geeksforgeeks.org/dsa/check-actual-binary-representation-number-palindrome/

⇱ Check if actual binary representation of a number is palindrome - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Check if actual binary representation of a number is palindrome

Last Updated : 1 Aug, 2022

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.

Examples : 

Input : 9
Output : Yes
(9)10 = (1001)2

Input : 10
Output : No
(10)10 = (1010)2

Approach: Following are the steps:

  1. Get the number obtained by reversing the bits in the binary representation of n. Refer this post. Let it be rev.
  2. If n == rev, then print "Yes" else "No".

Implementation:


Output
Yes

Time Complexity: O(num), where num is the number of bits in the binary representation of n.
Auxiliary Space: O(1).

Comment
Article Tags: