To check if binary representation of a number is palindrome in python; Through this tutorial, i am going to show you how to check if binary representation of a number is palindrome in python.
A positive number or string is said to be a palindrome if the reverse of the number or string is equal to the given number or string. For example, 141 is a palindrome but 142 is not.
Python program to check if binary representation is palindrome
- Python program to convert a given decimal number to binary number
- Python Program to Check Whether the Binary Equivalent of a Given Number is Palindrome
Python program to convert a given decimal number to binary number
- Get input number from user in python program.
- Convert number into a binary number.
- Print result.
# Python program to convert a given decimal number to binary number # take input the number from user x=int(input('Enter a number: ')) # convert into binary number y=int(bin(x)[2:]) # display the result print("The binary representation of number:", y)
Output
Enter a number: 17 The binary representation of number: 10001
Python Program to Check Whether the Binary Equivalent of a Given Number is Palindrome
- Get the input number from user by using input() function.
- Convert number into a binary number.
- To check the binary representation is a palindrome or not.
- Print result.
# Python Program to Check Whether the Binary Equivalent of a Given Number is Palindrome # take input the number user x=int(input('Enter a number: ')) # converting to binary y=int(bin(x)[2:]) # reversing the binary out=str(y)[::-1] print("The binary representation of number:", y) # checking the palindrome if int(out)==y: print("The binary representation of the number is a palindrome.") else: print("The binary representation of the number is not a palindrome.")
Output
Enter a number: 17 The binary representation of number: 10001 The binary representation of the number is a palindrome.
Recommended Python Tutorials
Recommended:-Python Program to Find Strong Number
Recommended:-Python Program to Convert cm to Feet and Inches
Recommended:-How to Reverse a List in Python
Recommended:-Python Program to Convert Celsius to Fahrenheit
Recommended:-Python Program to Find Standard Deviation
Recommended:-Python Program to Check Perfect Number
Recommended:-Python Program to Display Calendar
Recommended:-Python Program to Print Alphabets from A to Z
Recommended:-Python Program to Find Roots of Quadratic Equation
Recommended:-Python Program to Find the Variance
Recommended:-How to Check Python Program Execution Time
Recommended:-Python Program Find Day of Week For Given Date
Recommended:-Python Program to Print Sum of All Array Elements
Recommended:-Python Program to Find the GCD of Two Numbers
Recommended:-Python Program to Find the LCM of the Array Elements