Created
September 3, 2025 23:23
-
-
Save Osman8a/b9437155e6bd31884e146dd714e7f542 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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