Created
October 24, 2021 17:56
-
-
Save les-peters/7ba0e7382f856d71d2882c9e394764f5 to your computer and use it in GitHub Desktop.
add without plus
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
| def binOr(x, y): | |
| if x == '0' and y == '0': | |
| return 0 | |
| elif x == '1' and y == '1': | |
| return 2 | |
| else: | |
| return 1 | |
| a = 10 | |
| b = 20 | |
| bin_a = str(str(bin(a))[2::])[::-1] | |
| bin_b = str(str(bin(b))[2::])[::-1] | |
| l = len(bin_a) if len(bin_a) > len(bin_b) else len(bin_b) | |
| z = [] | |
| for i in range(l): | |
| try: | |
| c = bin_a[i] | |
| except: | |
| c = 0 | |
| try: | |
| d = bin_b[i] | |
| except: | |
| d = 0 | |
| z.insert(0,(str(binOr(c, d)))) | |
| print(str(int(''.join(z),2))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment