I'm having trouble trying to add these together correctly. I have kind of ran into a brick wall. I have gotten it converted and that's it as of now.
My Code:
I am not allowed to import math either.
Any help would be much appreciated! :]
My Code:
Code:
class BinaryNumber:
'''A Binary Number Class'''
#pass
def __init__(self, bitString = ''):
'''Constructor'''
#pass
self._bits = bitString
def __str__(self):
'''string representation'''
if self._bits:
return self._bits
else:
return '0'
def __int__(self):
'''conversion'''
#pass
total = 0
for pos in range(len(self._bits)):
if self._bits[pos] == '1':
total += 2 ** (len(self._bits) - 1 - pos)
return total
def __add__(self, other):
'''addition: implementation of the + operator'''
pass
Any help would be much appreciated! :]
Comment