I need to convert from binary values such as '1010' to decimal values. this needs to include negative binary.
def BinaryToDecimal (n):
n1 = n
decimal = 0
i = 0
n = 0
while(n != 0):
dec = n % 10
decimal = decimal + dec * pow(2, i)
n = n//10
i += 1
print(decimal)
This is what i have so far, but it doesn't work. I'm not sure what else to do. Please help! I am not allowed to use any fancy python libraries, I am supposed to write the code manually.