Sign_magnitude_adder using python

Viewed 23

I've generated 4bit binary numbers using python and I'm trying to do sign magnitude addition between the first two and the last two bits. Here is my code for generating the binary numbers:

#Generate binary 
n = 4
for i in xrange(16):
a = bin(i)[2:].zfill(n)
l = len(a)
r = a[0:1] + a[2:3]
print r

When I use r = a[0:1] + a[2:3] it adds the literal binary 0 and 1 together, I was wondering how can I actually add binary numbers together in python.

Thank you,

Note: I'm using python 2

0 Answers
Related