Saturday, November 22, 2025
HomeLanguagesFind all the co binary numbers in the given range.

Find all the co binary numbers in the given range.

Find the number of co-binary palindromes existing between m and n. A co-binary palindrome is a number in which both, the decimal number and its binary conversion are a palindrome.

Examples:

Input: starting number : 300, last number: 315

Output : 313

Code: Python code to find all the co binary numbers in the given range




# Python code for co-binary palindromes
  
def convert_into_binary(number):
    return bin(number).replace("0b","")
  
def reverse_it(number):
    number = str(number)
    return number[::-1]
  
def is_palindrome(number):
    if number == int(reverse_it(number)) :
        return True
    else:
        return False
  
# starting number
m = 300
  
# ending number
n = 1000
bin_pals = []
  
for i in range(m,n+1):
    if is_palindrome(i) == True and is_palindrome(
            int(convert_into_binary(i))):
          
        bin_pals.append(i)
          
print(bin_pals)


Output :

[313, 585, 717]
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32407 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6784 POSTS0 COMMENTS
Nicole Veronica
11929 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11999 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7168 POSTS0 COMMENTS
Thapelo Manthata
6863 POSTS0 COMMENTS
Umr Jansen
6847 POSTS0 COMMENTS