Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def binary_operator(n1, n2, o):
- if o == '+':
- out = bin(int(n1, 2) + int(n2, 2))[2:]
- return '0' * (16 - len(out)) + out
- elif o == '-':
- out = bin(abs(int(n1, 2) - int(n2, 2)))[2:]
- return '1' + '0' * (15 - len(out)) + out if (int(n1, 2) - int(n2, 2)) < 0 else '0' * (16 - len(out)) + out
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement