Advertisement
jotto

Untitled

May 27th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.32 KB | None | 0 0
  1. def binary_operator(n1, n2, o):
  2.     if o == '+':
  3.         out = bin(int(n1, 2) + int(n2, 2))[2:]
  4.         return '0' * (16 - len(out)) + out
  5.     elif o == '-':
  6.         out = bin(abs(int(n1, 2) - int(n2, 2)))[2:]
  7.         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