Professional Documents
Culture Documents
L13 - Binary Palindrome
L13 - Binary Palindrome
L13 - Binary Palindrome
Introduction
You are given an integer ‘X’, you need to convert the integer to binary format and
check if the binary format is palindrome or not
For Example, 5 i.e. 101, 27 i.e. 11011 are numbers whose binary representations
are palindromes. Wheras 10 i.e. 1011 and 20 i.e. 10100 are not palindromes
We start from leftmost and rightmost bits and compare bits one by one. If we find
a mismatch, then return false.
We can use the regular palindrome program. Converting integer ‘val’ to binary is
as easy as Integer.toBinaryString(val)
1. Binary palindrome of N=5
- Binary: 101
- Reversed binary: 101
- Explanation: The binary sequence reads the same forwards and backwards.
Sample IO
Input : 1
Output : 1
1st Number whose binary representation
is palindrome is 1 (1)
Input : 9
Output : 27
9th Number whose binary representation
is palindrome is 27 (11011)
THANK YOU