python - Error while converting binary to integer when the last bit is zero [low] -


i using manual method convert binary decimal. code works fine last bit high eg: 1001. error arises when last bit zero[low]. eg: 1010 should give 10 gives 5 because last bit not considered.could 1 me in this.

x=raw_input('enter binary value:') x=[int(xi) xi in x]  sum=0 in range(0,len(x)):     sum=sum+x[i]*(pow(2,i))  print sum 

you're misinterpreting problem. issue isn't it's ignoring last bit if it's 0, problem it's reading binary sequence backwards. when feed in "1010", processes "0101".

sum = sum + x[i] * (pow(2, len(x) - - 1)) 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -