Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Python Program to Check if binary representation is a palindrome

# Function to check if binary representation of
# a number is palindrome or not
 
def binarypalindrome(num):
 
     # convert number into binary
     binary = bin(num)
 
     # skip first two characters of string
     # because bin function appends '0b' as
     # prefix in binary representation of
     # a number
     binary = binary[2:]
 
     # now reverse binary string and compare
     # it with original
     return binary == binary[-1::-1]
 
# Driver program
if __name__ == "__main__":
    num = 9
    print binarypalindrome(num)
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #Python #Program #Check #binary #representation #palindrome
ADD COMMENT
Topic
Name
9+1 =