Skip to content

Instantly share code, notes, and snippets.

@les-peters
Created October 24, 2021 17:56
Show Gist options
  • Select an option

  • Save les-peters/7ba0e7382f856d71d2882c9e394764f5 to your computer and use it in GitHub Desktop.

Select an option

Save les-peters/7ba0e7382f856d71d2882c9e394764f5 to your computer and use it in GitHub Desktop.
add without plus
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