1+1 is 10 in binary and then you carry over the 1. I was wondering how to do that with Python? I was able to invert the binary and determine the sum of the rightmost bit and if it's 2, the rightmost digit would become 0. This is where I'm stuck at. I don't know how to carry over the 1. I was thinking of using the for function, and let it start from the right to the left using string indexing, but it gave me an error (TypeError: 'builtin_function_or_method' object is unsubscriptable).
This is part of the code that does what I just described.
elif s < bit: oldbitstring = str(int('1'*(bit-s) + b)) bitstring = str(int('1'*(bit-s) + b) + 1) if int(bitstring[-1]) == 2: oldbitstring = int(oldbitstring) - 1 print oldbitstring
*note bit would be the number of bits the user inputs. s would be the length of the binary after the decimal is converted.