Select Page

# Program to check if binary representation is palindrome using Python

by | Jul 15, 2021 | Python Programs

Home » Python » Python Programs » Program to check if binary representation is palindrome using Python

## Introduction

The task is to check whether the binary representation of the given number is palindrome or not.

## Program

```def check(ip_num):
# Convert the given number into binary format
convert = bin(ip_num)
# Ignore the first two characters (0b) appended while covertion
convert = convert[2:]
# Reverse the output and check
return convert == convert[-1::-1]

ip_num = int(input("Enter the number: "))
print("The  binary representation of {0} is Palindrome ? True/False : {1} ".format(ip_num,check(ip_num)) )```

## Output ## Explanation

Approach:

• Convert the given number to binary representation using python in-built bin() function.
• Reverse the converted string. (Ignore the first two character as while conversion 0b is inserted at start of string)
• Compare the original converted string with reversed string. If they are same then the binary string is palindrome.

## Author

• A Full Stack Developer with 10+ years of experience in technical content creation.

• 