Skip to content

Instantly share code, notes, and snippets.

@Osman8a
Created September 3, 2025 23:23
Show Gist options
  • Select an option

  • Save Osman8a/b9437155e6bd31884e146dd714e7f542 to your computer and use it in GitHub Desktop.

Select an option

Save Osman8a/b9437155e6bd31884e146dd714e7f542 to your computer and use it in GitHub Desktop.
import re
def invertir(num):
patron = r'^[0,1]\d[0,1]*[0,1]$'
is_binary = re.search(patron, str(num))
if is_binary:
reverse = str(num)[::-1]
return reverse
else:
to_binary = bin(int(num))[2:]
binary_reversed = to_binary[::-1]
return int(binary_reversed, 2)
value = invertir(43261596)
secondValue = invertir('00000010100101000001111010011100')
print(value)
print(secondValue)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment